Browse Source

Make UPDATE_ACCOUNT a standard redux action

master
meriadec 7 years ago
parent
commit
7627785d8b
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 13
      src/actions/accounts.js
  2. 4
      src/reducers/accounts.js

13
src/actions/accounts.js

@ -67,9 +67,8 @@ export const fetchAccounts: FetchAccounts = () => (dispatch, getState) => {
export type UpdateAccountWithUpdater = (accountId: string, (Account) => Account) => *
export const updateAccountWithUpdater: UpdateAccountWithUpdater = (accountId, updater) => ({
type: 'UPDATE_ACCOUNT',
accountId,
updater,
type: 'DB:UPDATE_ACCOUNT',
payload: { accountId, updater },
})
export type UpdateAccount = ($Shape<Account>) => (Function, Function) => void
@ -78,9 +77,11 @@ export const updateAccount: UpdateAccount = payload => (dispatch, getState) => {
settings: { orderAccounts },
} = getState()
dispatch({
type: 'UPDATE_ACCOUNT',
updater: account => ({ ...account, ...payload }),
accountId: payload.id,
type: 'DB:UPDATE_ACCOUNT',
payload: {
updater: account => ({ ...account, ...payload }),
accountId: payload.id,
},
})
dispatch(updateOrderAccounts(orderAccounts))
// TODO should not be here IMO.. feels wrong for perf, probably better to move in reducer too

4
src/reducers/accounts.js

@ -30,7 +30,9 @@ const handlers: Object = {
UPDATE_ACCOUNT: (
state: AccountsState,
{ accountId, updater }: { accountId: string, updater: Account => Account },
{
payload: { accountId, updater },
}: { payload: { accountId: string, updater: Account => Account } },
): AccountsState =>
state.map(existingAccount => {
if (existingAccount.id !== accountId) {

Loading…
Cancel
Save