Store all settings in the scoped property store

There are a few failing specs, but I think they can all be addressed by
having a `source` for all properties and using it to target only the
user settings in various cases.
Esse commit está contido em:
Nathan Sobo
2014-12-11 21:03:11 -07:00
commit de Max Brunsfeld
commit b7b5852863
+23 -10
Ver Arquivo
@@ -564,7 +564,7 @@ class Config
if scopeSelector?
@setRawScopedValue(source, scopeSelector, keyPath, value)
else
@setRawValue(keyPath, value)
@setRawValue(source, keyPath, value)
@save() unless @configFileHasErrors
true
@@ -666,7 +666,7 @@ class Config
# defaults. Returns the scoped settings when a `scopeSelector` is specified.
getSettings: ->
Grim.deprecate "Use ::get(keyPath) instead"
_.deepExtend({}, @settings, @defaultSettings)
_.deepExtend({}, @defaultSettings, @scopedSettingsStore.getProperties('.xxx')...)
# Extended: Get the {String} path to the config file being used.
getUserConfigPath: ->
@@ -836,7 +836,7 @@ class Config
continue unless value.hasOwnProperty(key)
unsetUnspecifiedValues(keys.concat([key]).join('.'), childValue)
else
@setRawValue(keyPath, undefined) unless _.valueForKeyPath(newSettings, keyPath)?
@setRawValue(@getUserConfigPath(), keyPath, undefined) unless _.valueForKeyPath(newSettings, keyPath)?
return
@setRecursive(null, newSettings)
@@ -851,13 +851,12 @@ class Config
else
try
value = @makeValueConformToSchema(keyPath, value)
@setRawValue(keyPath, value)
@setRawValue(@getUserConfigPath(), keyPath, value)
catch e
console.warn("'#{keyPath}' could not be set. Attempted value: #{JSON.stringify(value)}; Schema: #{JSON.stringify(@getSchema(keyPath))}")
getRawValue: (keyPath, options) ->
unless options?.excludeSources?.indexOf(@getUserConfigPath()) >= 0
value = _.valueForKeyPath(@settings, keyPath)
value = @getRawScopedValue(['xxx'], keyPath, options)
unless options?.sources?.length > 0
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
@@ -869,11 +868,10 @@ class Config
value
setRawValue: (keyPath, value) ->
setRawValue: (source, keyPath, value) ->
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
value = undefined if _.isEqual(defaultValue, value)
_.setValueForKeyPath(@settings, keyPath, value)
@setRawScopedValue(source, '*', keyPath, value)
@emitChangeEvent()
observeKeyPath: (keyPath, options, callback) ->
@@ -977,7 +975,7 @@ class Config
setRawScopedValue: (source, selector, keyPath, value) ->
if keyPath?
newValue = {}
_.setValueForKeyPath(newValue, keyPath, value)
setValueAtKeyPath(newValue, keyPath, value)
value = newValue
settingsBySelector = {}
@@ -1127,6 +1125,21 @@ splitKeyPath = (keyPath) ->
keyPathArray.push keyPath.substr(startIndex, keyPath.length)
keyPathArray
getValueAtKeyPath = (object, keyPath) ->
keys = splitKeyPath(keyPath)
for key in keys
object = object[key]
return unless object?
object
setValueAtKeyPath = (object, keyPath, value) ->
keys = splitKeyPath(keyPath)
while keys.length > 1
key = keys.shift()
object[key] ?= {}
object = object[key]
object[keys.shift()] = value
withoutEmptyObjects = (object) ->
resultObject = undefined
if isPlainObject(object)