When observing a key path, compare its new & old values structurally

This commit is contained in:
Nathan Sobo 2012-12-17 19:00:47 -07:00
parent a7d1a29748
commit b82fe25b99
2 changed files with 6 additions and 2 deletions

View File

@ -25,13 +25,17 @@ describe "Config", ->
config.get("foo.bar.baz").push("b")
config.update()
expect(observeHandler).toHaveBeenCalledWith config.get("foo.bar.baz")
observeHandler.reset()
config.update()
expect(observeHandler).not.toHaveBeenCalled()
describe ".observe(keyPath)", ->
observeHandler = null
beforeEach ->
observeHandler = jasmine.createSpy("observeHandler")
config.foo = { bar: { baz: "value 1" } }
config.set("foo.bar.baz", "value 1")
config.observe "foo.bar.baz", observeHandler
it "fires the given callback with the current value at the keypath", ->

View File

@ -83,7 +83,7 @@ class Config
previousValue = _.clone(value)
updateCallback = =>
value = @get(keyPath)
unless value == previousValue
unless _.isEqual(value, previousValue)
previousValue = _.clone(value)
callback(value)