Commit list accounts state after difference in removed accounts is determined #82

Merged
floatingghost merged 2 commits from :commit-list-accounts-after-delete into develop 2022-08-01 10:11:40 +00:00

View file

@ -57,12 +57,16 @@ const actions = {
commit('setList', { id, title })
},
setListAccounts ({ rootState, commit }, { id, accountIds }) {
const saved = rootState.lists.allListsObject[id].accountIds
const added = accountIds.filter(id => !saved.includes(id))
const removed = saved.filter(id => !accountIds.includes(id))
commit('setListAccounts', { id, accountIds })
rootState.api.backendInteractor.addAccountsToList({ id, accountIds })
rootState.api.backendInteractor.removeAccountsFromList({
id,
accountIds: rootState.lists.allListsObject[id].accountIds.filter(id => !accountIds.includes(id))
})
if (added.length > 0) {
rootState.api.backendInteractor.addAccountsToList({ id, accountIds: added })
}
if (removed.length > 0) {
rootState.api.backendInteractor.removeAccountsFromList({ id, accountIds: removed })
}
},
deleteList ({ rootState, commit }, { id }) {
rootState.api.backendInteractor.deleteList({ id })
@ -76,7 +80,7 @@ export const getters = {
return state.allListsObject[id].title
},
findListAccounts: state => id => {
return state.allListsObject[id].accountIds
return [...state.allListsObject[id].accountIds]
Ghost marked this conversation as resolved Outdated

the preferred way to duplicate an array is via the ... syntax

return [...state.allListsObject[id].accountIds]

the preferred way to duplicate an array is via the `...` syntax `return [...state.allListsObject[id].accountIds]`
Outdated
Review

As far as performance goes, ths is less optimal option. But if you want to prioritize readability, sure.

As far as performance goes, ths is less optimal option. But if you want to prioritize readability, sure.

the difference in performance would only actually be relevent if we were dealing with (tens of) thousands of elements, which we're not

the difference in performance would only actually be relevent if we were dealing with (tens of) thousands of elements, which we're not
}
}