mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
When observing a key path, compare its new & old values structurally
This commit is contained in:
parent
a7d1a29748
commit
b82fe25b99
@ -25,13 +25,17 @@ describe "Config", ->
|
|||||||
config.get("foo.bar.baz").push("b")
|
config.get("foo.bar.baz").push("b")
|
||||||
config.update()
|
config.update()
|
||||||
expect(observeHandler).toHaveBeenCalledWith config.get("foo.bar.baz")
|
expect(observeHandler).toHaveBeenCalledWith config.get("foo.bar.baz")
|
||||||
|
observeHandler.reset()
|
||||||
|
|
||||||
|
config.update()
|
||||||
|
expect(observeHandler).not.toHaveBeenCalled()
|
||||||
|
|
||||||
describe ".observe(keyPath)", ->
|
describe ".observe(keyPath)", ->
|
||||||
observeHandler = null
|
observeHandler = null
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
observeHandler = jasmine.createSpy("observeHandler")
|
observeHandler = jasmine.createSpy("observeHandler")
|
||||||
config.foo = { bar: { baz: "value 1" } }
|
config.set("foo.bar.baz", "value 1")
|
||||||
config.observe "foo.bar.baz", observeHandler
|
config.observe "foo.bar.baz", observeHandler
|
||||||
|
|
||||||
it "fires the given callback with the current value at the keypath", ->
|
it "fires the given callback with the current value at the keypath", ->
|
||||||
|
@ -83,7 +83,7 @@ class Config
|
|||||||
previousValue = _.clone(value)
|
previousValue = _.clone(value)
|
||||||
updateCallback = =>
|
updateCallback = =>
|
||||||
value = @get(keyPath)
|
value = @get(keyPath)
|
||||||
unless value == previousValue
|
unless _.isEqual(value, previousValue)
|
||||||
previousValue = _.clone(value)
|
previousValue = _.clone(value)
|
||||||
callback(value)
|
callback(value)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user