Use _.isEqual when comparing value to default

This commit is contained in:
Kevin Sawicki
2014-04-17 10:15:20 -07:00
parent 20c3ca21e3
commit 35d268fcf8
2 changed files with 7 additions and 3 deletions

View File

@@ -36,10 +36,13 @@ describe "Config", ->
describe "when the value equals the default value", ->
it "does not store the value", ->
atom.config.setDefaults("foo", same: 1, changes: 1)
atom.config.setDefaults("foo", same: 1, changes: 1, sameArray: [1, 2, 3], null: null, undefined: undefined)
expect(atom.config.settings.foo).toBeUndefined()
atom.config.set('foo.same', 1)
atom.config.set('foo.changes', 2)
atom.config.set('foo.sameArray', [1, 2, 3])
atom.config.set('foo.null', undefined)
atom.config.set('foo.undefined', null)
expect(atom.config.settings.foo).toEqual {changes: 2}
atom.config.set('foo.changes', 1)

View File

@@ -135,8 +135,9 @@ class Config
#
# Returns the `value`.
set: (keyPath, value) ->
if @get(keyPath) != value
value = undefined if _.valueForKeyPath(@defaultSettings, keyPath) == value
if @get(keyPath) isnt value
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
value = undefined if _.isEqual(defaultValue, value)
_.setValueForKeyPath(@settings, keyPath, value)
@update()
value