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

Loading…
Cancel
Save