mirror of
https://github.com/atom/atom.git
synced 2026-02-17 10:01:25 -05:00
Return a cloned object from config.get()
This prevents mutations to the values of the default settings.
This commit is contained in:
@@ -106,8 +106,8 @@ class Config
|
||||
# Returns the value from Atom's default settings, the user's configuration file,
|
||||
# or `null` if the key doesn't exist in either.
|
||||
get: (keyPath) ->
|
||||
_.valueForKeyPath(@settings, keyPath) ?
|
||||
_.valueForKeyPath(@defaultSettings, keyPath)
|
||||
value = _.valueForKeyPath(@settings, keyPath) ? _.valueForKeyPath(@defaultSettings, keyPath)
|
||||
_.deepClone(value)
|
||||
|
||||
# Retrieves the setting for the given key as an integer.
|
||||
#
|
||||
|
||||
@@ -29,11 +29,12 @@ class PackageConfigPanel extends ConfigPanel
|
||||
@on 'change', '#packages input[type=checkbox]', (e) ->
|
||||
checkbox = $(e.target)
|
||||
name = checkbox.closest('tr').attr('name')
|
||||
disabledPackages = config.get('core.disabledPackages')
|
||||
if checkbox.attr('checked')
|
||||
_.remove(config.get('core.disabledPackages'), name)
|
||||
_.remove(disabledPackages, name)
|
||||
else
|
||||
config.get('core.disabledPackages').push(name)
|
||||
config.update()
|
||||
disabledPackages.push(name)
|
||||
config.set('core.disabledPackages', disabledPackages)
|
||||
|
||||
@observeConfig 'core.disabledPackages', (disabledPackages) =>
|
||||
@packageTableBody.find("input[type='checkbox']").attr('checked', true)
|
||||
|
||||
@@ -126,6 +126,35 @@ _.mixin
|
||||
endsWith: (string, suffix) ->
|
||||
string.indexOf(suffix, string.length - suffix.length) isnt -1
|
||||
|
||||
# Transform the given object into another object.
|
||||
#
|
||||
# `object` - The object to transform.
|
||||
# `iterator` -
|
||||
# A function that takes `(key, value)` arguments and returns a
|
||||
# `[key, value]` tuple.
|
||||
#
|
||||
# Returns a new object based with the key/values returned by the iterator.
|
||||
mapObject: (object, iterator) ->
|
||||
newObject = {}
|
||||
for key, value of object
|
||||
[key, value] = iterator(key, value)
|
||||
newObject[key] = value
|
||||
|
||||
newObject
|
||||
|
||||
# Deep clones the given JSON object.
|
||||
#
|
||||
# `object` - The JSON object to clone.
|
||||
#
|
||||
# Returns a deep clone of the JSON object.
|
||||
deepClone: (object) ->
|
||||
if _.isArray(object)
|
||||
object.map (value) -> _.deepClone(value)
|
||||
else if _.isObject(object)
|
||||
@mapObject object, (key, value) => [key, @deepClone(value)]
|
||||
else
|
||||
object
|
||||
|
||||
valueForKeyPath: (object, keyPath) ->
|
||||
keys = keyPath.split('.')
|
||||
for key in keys
|
||||
|
||||
Reference in New Issue
Block a user