Setting value to null/undefined removes key from config

This commit is contained in:
Corey Johnson & Nathan Sobo
2013-04-25 17:52:29 -07:00
committed by Corey Johnson & Kevin Sawicki
parent c923b561e2
commit 1b98bf706e
2 changed files with 9 additions and 1 deletions

View File

@@ -100,6 +100,11 @@ describe "Config", ->
config.set('foo.bar.baz', "value 1")
expect(observeHandler).toHaveBeenCalledWith("value 1")
it "fires the callback when the observed value is deleted", ->
observeHandler.reset() # clear the initial call
config.set('foo.bar.baz', undefined)
expect(observeHandler).toHaveBeenCalledWith(undefined)
it "fires the callback when the full key path goes into and out of existence", ->
observeHandler.reset() # clear the initial call
config.set("foo.bar", undefined)

View File

@@ -139,7 +139,10 @@ _.mixin
key = keys.shift()
object[key] ?= {}
object = object[key]
object[keys.shift()] = value
if value?
object[keys.shift()] = value
else
delete object[keys.shift()]
compactObject: (object) ->
newObject = {}