fix: make accounts a object
This commit is contained in:
parent
ec73f0b022
commit
6b3db134e7
7 changed files with 26 additions and 38 deletions
|
|
@ -9,20 +9,11 @@ low(adapter).then(it => {
|
|||
db = it
|
||||
})
|
||||
|
||||
function replace (array, index, value) {
|
||||
return array.slice(0, index).concat([value]).concat(array.slice(index + 1))
|
||||
}
|
||||
|
||||
function replaceOrAdd (accounts, account) {
|
||||
const index = _.findIndex(['code', account.code], accounts)
|
||||
return index !== -1 ? replace(accounts, index, account) : _.concat(accounts)(account)
|
||||
}
|
||||
|
||||
function saveAccounts (accountsToSave) {
|
||||
const currentState = db.getState() || {}
|
||||
const accounts = currentState.accounts || []
|
||||
const accounts = currentState.accounts || {}
|
||||
|
||||
const newAccounts = _.reduce(replaceOrAdd)(accounts)(accountsToSave)
|
||||
const newAccounts = _.assign(accounts)(accountsToSave)
|
||||
|
||||
const newState = _.set('accounts', newAccounts, currentState)
|
||||
db.setState(newState)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue