fix(config): removeAtKeyPath => undo, guard with assertions

This commit is contained in:
Ben Gotow 2016-05-25 11:03:38 -07:00
parent 48556bef98
commit 3fdffb4b81
2 changed files with 7 additions and 1 deletions

View file

@ -111,7 +111,7 @@ class NylasLongConnection
res.on 'data', (chunk) =>
if chunk.toString().indexOf('Invalid cursor') > 0
error = new Error('Delta Connection: Cursor is invalid. Need to blow away local cache.')
NylasEnv.config.removeAtKeyPath("nylas.#{@_accountId}.cursor")
NylasEnv.config.unset("nylas.#{@_accountId}.cursor")
DatabaseStore._handleSetupError(error)
@close()
return

View file

@ -485,18 +485,24 @@ class Config
pushAtKeyPath: (keyPath, value) ->
arrayValue = @get(keyPath) ? []
unless arrayValue instanceof Array
throw new Error("Config.pushAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.")
result = arrayValue.push(value)
@set(keyPath, arrayValue)
result
unshiftAtKeyPath: (keyPath, value) ->
arrayValue = @get(keyPath) ? []
unless arrayValue instanceof Array
throw new Error("Config.unshiftAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.")
result = arrayValue.unshift(value)
@set(keyPath, arrayValue)
result
removeAtKeyPath: (keyPath, value) ->
arrayValue = @get(keyPath) ? []
unless arrayValue instanceof Array
throw new Error("Config.removeAtKeyPath is intended for array values. Value #{JSON.stringify(arrayValue)} is not an array.")
result = _.remove(arrayValue, value)
@set(keyPath, arrayValue)
result