mirror of
https://github.com/atom/atom.git
synced 2026-02-17 18:11:29 -05:00
Add config.pushAtKeyPath/removeAtKeyPath
This commit is contained in:
@@ -144,6 +144,30 @@ class Config
|
||||
@update()
|
||||
value
|
||||
|
||||
# Push the value to the array at the key path.
|
||||
#
|
||||
# keyPath - The {String} key path.
|
||||
# value - The value to push to the array.
|
||||
#
|
||||
# Returns the new array length of the setting.
|
||||
pushAtKeyPath: (keyPath, value) ->
|
||||
arrayValue = @get(keyPath) ? []
|
||||
result = arrayValue.push(value)
|
||||
@set(keyPath, arrayValue)
|
||||
result
|
||||
|
||||
# Remove the value from the array at the key path.
|
||||
#
|
||||
# keyPath - The {String} key path.
|
||||
# value - The value to remove from the array.
|
||||
#
|
||||
# Returns the new array value of the setting.
|
||||
removeAtKeyPath: (keyPath, value) ->
|
||||
arrayValue = @get(keyPath) ? []
|
||||
result = _.remove(arrayValue, value)
|
||||
@set(keyPath, arrayValue)
|
||||
result
|
||||
|
||||
# Establishes an event listener for a given key.
|
||||
#
|
||||
# `callback` is fired immediately and whenever the value of the key is changed
|
||||
|
||||
@@ -29,12 +29,10 @@ 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(disabledPackages, name)
|
||||
config.removeAtKeyPath('core.disabledPackages', name)
|
||||
else
|
||||
disabledPackages.push(name)
|
||||
config.set('core.disabledPackages', disabledPackages)
|
||||
config.pushAtKeyPath('core.disabledPackages', name)
|
||||
|
||||
@observeConfig 'core.disabledPackages', (disabledPackages) =>
|
||||
@packageTableBody.find("input[type='checkbox']").attr('checked', true)
|
||||
|
||||
@@ -4,6 +4,7 @@ _.mixin
|
||||
remove: (array, element) ->
|
||||
index = array.indexOf(element)
|
||||
array.splice(index, 1) if index >= 0
|
||||
array
|
||||
|
||||
spliceWithArray: (originalArray, start, length, insertedArray, chunkSize=100000) ->
|
||||
if insertedArray.length < chunkSize
|
||||
|
||||
Reference in New Issue
Block a user