-
Notifications
You must be signed in to change notification settings - Fork 296
Closed
Description
In normal reducers we can use fallthrough to use the same reducing method for multiple action types. What's the easy way to do this in redux-actions
?
// normal reducer
switch (action.type) {
case FETCH_ERROR:
case CREATE_ERROR:
case EDIT_ERROR:
case DELETE_ERROR:
return state
.set('phase', ERROR)
.set('error', String(action.payload.error));
default:
return state;
}
// redux-actions
handleActions({
[FETCH_ERROR]: (state, { payload }) => state
.set('phase', ERROR)
.set('error', String(payload.error));
[CREATE_ERROR]: (state, { payload }) => state
.set('phase', ERROR)
.set('error', String(payload.error));
[EDIT_ERROR]: (state, { payload }) => state
.set('phase', ERROR)
.set('error', String(payload.error));
[DELETE_ERROR]: (state, { payload }) => state
.set('phase', ERROR)
.set('error', String(payload.error));
}, {});
Is this even possible?
I realize I can create a small helper function, and call this function 4 times, but still it doesn't look very nice:
// redux-actions
const setError = (state, { payload }) => state
.set('phase', ERROR)
.set('error', String(payload.error));
handleActions({
[FETCH_ERROR]: setError,
[CREATE_ERROR]: setError,
[EDIT_ERROR]: setError,
[DELETE_ERROR]: setError,
}, {});
Anyone with suggestions to handle this in a clean way?
Metadata
Metadata
Assignees
Labels
No labels