Return emissary subscription directly

This commit is contained in:
Kevin Sawicki
2013-11-18 18:41:15 -08:00
parent 89d8eac091
commit f55a200591
3 changed files with 10 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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