Reputation: 1739
const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state /*do sth other */})),
on(loginSuccessful, loginFailed, (state) => ({...state, isLogging: false}))
);
In example above I have shared logic between multiple actions (isLogging
property).
But only one of these reducers will be fired when loginSuccesfull action was dispatched.
It is possible to connect shared logic instead of writing:
const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state, isLogging: false /*do sth other */})),
on(loginFailed, (state) => ({...state, isLogging: false}))
);
Upvotes: 1
Views: 39
Reputation: 15505
This is not possible (for now), only the last registered action of the same action's type receives the update.
const authReducer = createReducer(
initialState,
on(startLogin, (state) => ({...state, isLogging: true})),
on(loginSuccessful, (state) => ({...state /*do sth other */})),
on(loginSuccessful, loginFailed, (state) => ({...state, isLogging: false})) // only this one will be triggered for loginSuccessful
);
We just merged a PR to make your use case possible, this will probably get "out" with the next release.
Upvotes: 2