mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #8480 from jeremyramin/fix-config-get
Fix config.get for schemas with objects
This commit is contained in:
@@ -1110,6 +1110,24 @@ describe "Config", ->
|
||||
nestedObject:
|
||||
superNestedInt: 36
|
||||
|
||||
expect(atom.config.get("foo")).toEqual {
|
||||
bar:
|
||||
anInt: 12
|
||||
anObject:
|
||||
nestedInt: 24
|
||||
nestedObject:
|
||||
superNestedInt: 36
|
||||
}
|
||||
atom.config.set("foo.bar.anObject.nestedObject.superNestedInt", 37)
|
||||
expect(atom.config.get("foo")).toEqual {
|
||||
bar:
|
||||
anInt: 12
|
||||
anObject:
|
||||
nestedInt: 24
|
||||
nestedObject:
|
||||
superNestedInt: 37
|
||||
}
|
||||
|
||||
it 'can set a non-object schema', ->
|
||||
schema =
|
||||
type: 'integer'
|
||||
|
||||
@@ -865,7 +865,7 @@ class Config
|
||||
|
||||
if value?
|
||||
value = @deepClone(value)
|
||||
_.defaults(value, defaultValue) if isPlainObject(value) and isPlainObject(defaultValue)
|
||||
@deepDefaults(value, defaultValue) if isPlainObject(value) and isPlainObject(defaultValue)
|
||||
else
|
||||
value = @deepClone(defaultValue)
|
||||
|
||||
@@ -928,6 +928,19 @@ class Config
|
||||
else
|
||||
object
|
||||
|
||||
deepDefaults: (target) ->
|
||||
result = target
|
||||
i = 0
|
||||
while ++i < arguments.length
|
||||
object = arguments[i]
|
||||
if isPlainObject(result) and isPlainObject(object)
|
||||
for key in Object.keys(object)
|
||||
result[key] = @deepDefaults(result[key], object[key])
|
||||
else
|
||||
if not result?
|
||||
result = @deepClone(object)
|
||||
result
|
||||
|
||||
# `schema` will look something like this
|
||||
#
|
||||
# ```coffee
|
||||
|
||||
Reference in New Issue
Block a user