fallthrough actions
See original GitHub issueIn 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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
C++ attribute: fallthrough (since C++17) - cppreference.com
Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on ......
Read more >Code Inspection: Fallthrough in 'switch' statement - JetBrains
Show intention actions: Alt+Enter. Reports a switch statement where control can proceed from a branch to the next one. Such "fall-through" ...
Read more >How to fallthrough to a specific case in switch statement
A fallthrough statement causes program execution to continue from one case in a switch statement to the next case. Program execution continues ...
Read more >How To Write Switch Statements in Go - DigitalOcean
Switch is commonly used to describe the actions taken by a program ... body of the next case clause listed using the fallthrough...
Read more >Fall through on switch case - warnings? : r/cpp - Reddit
So, for years, in both c and c++, I've used a technique where a case: does a bunch of stuff, call it X,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
have you checked
combineActions
?Actually, this is taken care of in https://github.com/acdlite/redux-actions/pull/165/files.