Handle null key-path in Config::set

This commit is contained in:
Max Brunsfeld
2014-12-26 14:58:17 -08:00
parent 3edd2f9590
commit dbaef8e593
2 changed files with 12 additions and 2 deletions

View File

@@ -112,6 +112,13 @@ describe "Config", ->
it "does not allow a 'source' option without a 'scopeSelector'", ->
expect(-> atom.config.set("foo", 1, source: [".source.ruby"])).toThrow()
describe "when the key-path is null", ->
it "sets the root object", ->
expect(atom.config.set(null, editor: tabLength: 6)).toBe true
expect(atom.config.get("editor.tabLength")).toBe 6
expect(atom.config.set(null, editor: tabLength: 8, scopeSelector: ['.source.js'])).toBe true
expect(atom.config.get("editor.tabLength", scope: ['.source.js'])).toBe 8
describe "when the value equals the default value", ->
it "does not store the value in the user's config", ->
atom.config.setDefaults "foo",

View File

@@ -539,7 +539,7 @@ class Config
# * `true` if the value was set.
# * `false` if the value was not able to be coerced to the type specified in the setting's schema.
set: ->
if arguments[0][0] is '.'
if arguments[0]?[0] is '.'
Grim.deprecate """
Passing a scope selector as the first argument to Config::set is deprecated.
Pass a `scopeSelector` in an options hash as the final argument instead.
@@ -856,7 +856,10 @@ class Config
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
value = undefined if _.isEqual(defaultValue, value)
_.setValueForKeyPath(@settings, keyPath, value)
if keyPath?
_.setValueForKeyPath(@settings, keyPath, value)
else
@settings = value
@emitChangeEvent()
observeKeyPath: (keyPath, options, callback) ->