diff --git a/spec/app/config-spec.coffee b/spec/app/config-spec.coffee index f0393d0af..7bfe22e2f 100644 --- a/spec/app/config-spec.coffee +++ b/spec/app/config-spec.coffee @@ -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) diff --git a/src/stdlib/underscore-extensions.coffee b/src/stdlib/underscore-extensions.coffee index defdb576f..d89bc99b7 100644 --- a/src/stdlib/underscore-extensions.coffee +++ b/src/stdlib/underscore-extensions.coffee @@ -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 = {}