mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Merge pull request #9131 from atom/mb-fix-config-unset
Fix setting default values in config
This commit is contained in:
commit
395ffde7a1
@ -31,7 +31,7 @@
|
||||
"jasmine-json": "~0.0",
|
||||
"jasmine-tagged": "^1.1.4",
|
||||
"jquery": "^2.1.1",
|
||||
"key-path-helpers": "^0.3.0",
|
||||
"key-path-helpers": "^0.4.0",
|
||||
"less-cache": "0.22",
|
||||
"marked": "^0.3.4",
|
||||
"normalize-package-data": "^2.0.0",
|
||||
|
@ -153,13 +153,27 @@ describe "Config", ->
|
||||
|
||||
describe "when the value equals the default value", ->
|
||||
it "does not store the value in the user's config", ->
|
||||
atom.config.setDefaults "foo",
|
||||
same: 1
|
||||
changes: 1
|
||||
sameArray: [1, 2, 3]
|
||||
sameObject: {a: 1, b: 2}
|
||||
null: null
|
||||
undefined: undefined
|
||||
atom.config.setSchema "foo",
|
||||
type: 'object'
|
||||
properties:
|
||||
same:
|
||||
type: 'number'
|
||||
default: 1
|
||||
changes:
|
||||
type: 'number'
|
||||
default: 1
|
||||
sameArray:
|
||||
type: 'array'
|
||||
default: [1, 2, 3]
|
||||
sameObject:
|
||||
type: 'object'
|
||||
default: {a: 1, b: 2}
|
||||
null:
|
||||
type: '*'
|
||||
default: null
|
||||
undefined:
|
||||
type: '*'
|
||||
default: undefined
|
||||
expect(atom.config.settings.foo).toBeUndefined()
|
||||
|
||||
atom.config.set('foo.same', 1)
|
||||
@ -169,11 +183,15 @@ describe "Config", ->
|
||||
atom.config.set('foo.undefined', null)
|
||||
atom.config.set('foo.sameObject', {b: 2, a: 1})
|
||||
|
||||
expect(atom.config.get("foo.same", sources: [atom.config.getUserConfigPath()])).toBeUndefined()
|
||||
userConfigPath = atom.config.getUserConfigPath()
|
||||
|
||||
expect(atom.config.get("foo.same", sources: [userConfigPath])).toBeUndefined()
|
||||
|
||||
expect(atom.config.get("foo.changes")).toBe 2
|
||||
expect(atom.config.get("foo.changes", sources: [userConfigPath])).toBe 2
|
||||
|
||||
expect(atom.config.get("foo.changes", sources: [atom.config.getUserConfigPath()])).toBe 2
|
||||
atom.config.set('foo.changes', 1)
|
||||
expect(atom.config.get("foo.changes", sources: [atom.config.getUserConfigPath()])).toBeUndefined()
|
||||
expect(atom.config.get("foo.changes", sources: [userConfigPath])).toBeUndefined()
|
||||
|
||||
describe "when a 'scopeSelector' is given", ->
|
||||
it "sets the value and overrides the others", ->
|
||||
|
@ -5,7 +5,10 @@ CSON = require 'season'
|
||||
path = require 'path'
|
||||
async = require 'async'
|
||||
pathWatcher = require 'pathwatcher'
|
||||
{pushKeyPath, splitKeyPath, getValueAtKeyPath, setValueAtKeyPath} = require 'key-path-helpers'
|
||||
{
|
||||
getValueAtKeyPath, setValueAtKeyPath, deleteValueAtKeyPath,
|
||||
pushKeyPath, splitKeyPath,
|
||||
} = require 'key-path-helpers'
|
||||
|
||||
Color = require './color'
|
||||
ScopedPropertyStore = require 'scoped-property-store'
|
||||
@ -832,12 +835,16 @@ class Config
|
||||
|
||||
setRawValue: (keyPath, value) ->
|
||||
defaultValue = getValueAtKeyPath(@defaultSettings, keyPath)
|
||||
value = undefined if _.isEqual(defaultValue, value)
|
||||
|
||||
if keyPath?
|
||||
setValueAtKeyPath(@settings, keyPath, value)
|
||||
if _.isEqual(defaultValue, value)
|
||||
if keyPath?
|
||||
deleteValueAtKeyPath(@settings, keyPath)
|
||||
else
|
||||
@settings = null
|
||||
else
|
||||
@settings = value
|
||||
if keyPath?
|
||||
setValueAtKeyPath(@settings, keyPath, value)
|
||||
else
|
||||
@settings = value
|
||||
@emitChangeEvent()
|
||||
|
||||
observeKeyPath: (keyPath, options, callback) ->
|
||||
|
Loading…
Reference in New Issue
Block a user