mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Return emissary subscription directly
This commit is contained in:
@@ -158,12 +158,12 @@ describe "Config", ->
|
||||
expect(atom.config.get("foo.quux.y")).toBe 1
|
||||
|
||||
describe ".observe(keyPath)", ->
|
||||
observeHandler = null
|
||||
[observeHandler, observeSubscription] = []
|
||||
|
||||
beforeEach ->
|
||||
observeHandler = jasmine.createSpy("observeHandler")
|
||||
atom.config.set("foo.bar.baz", "value 1")
|
||||
atom.config.observe "foo.bar.baz", observeHandler
|
||||
observeSubscription = atom.config.observe "foo.bar.baz", observeHandler
|
||||
|
||||
it "fires the given callback with the current value at the keypath", ->
|
||||
expect(observeHandler).toHaveBeenCalledWith("value 1")
|
||||
@@ -192,6 +192,12 @@ describe "Config", ->
|
||||
atom.config.set("foo.bar.baz", "i'm back")
|
||||
expect(observeHandler).toHaveBeenCalledWith("i'm back", {previous: undefined})
|
||||
|
||||
it "does not fire the callback once the observe subscription is off'ed", ->
|
||||
observeHandler.reset() # clear the initial call
|
||||
observeSubscription.off()
|
||||
atom.config.set('foo.bar.baz', "value 2")
|
||||
expect(observeHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe ".initializeConfigDirectory()", ->
|
||||
beforeEach ->
|
||||
atom.config.configDirPath = dotAtomPath
|
||||
|
||||
@@ -5,5 +5,5 @@ module.exports =
|
||||
|
||||
unobserveConfig: ->
|
||||
if @configSubscriptions?
|
||||
subscription.cancel() for keyPath, subscription of @configSubscriptions
|
||||
subscription.off() for keyPath, subscription of @configSubscriptions
|
||||
@configSubscriptions = null
|
||||
|
||||
@@ -216,8 +216,7 @@ class Config
|
||||
callback(value, {previous})
|
||||
|
||||
eventName = "updated.#{keyPath.replace(/\./, '-')}"
|
||||
subscription = { cancel: => @off eventName, updateCallback }
|
||||
@on eventName, updateCallback
|
||||
subscription = @on eventName, updateCallback
|
||||
callback(value) if options.callNow ? true
|
||||
subscription
|
||||
|
||||
|
||||
Reference in New Issue
Block a user