https://github.com/padcom/redux-action-reducer-mapper
Easy creation of reducers for Redux
https://github.com/padcom/redux-action-reducer-mapper
Last synced: 11 months ago
JSON representation
Easy creation of reducers for Redux
- Host: GitHub
- URL: https://github.com/padcom/redux-action-reducer-mapper
- Owner: padcom
- License: apache-2.0
- Created: 2016-06-27T21:47:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-27T23:12:45.000Z (almost 10 years ago)
- Last Synced: 2025-06-05T14:41:51.444Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/redux-action-reducer-mapper
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A mapper that makes it easy to create reducers based on a set of closures mapped to actions.
Use it instead of a gigantic and highly complex (in terms of cyclomatic code complexity) ```switch``` statement:
```
import mapActionToReducer from 'redux-action-reducer-mapper';
const reducer = mapActionToReducer({
'default': '',
'MY_ACTION': (state, action) => action.payload
})
```
is an equivalent of
```
const reducer = (state = '', action) => {
switch(action.type) {
case 'MY_ACTION':
return action.payload;
default:
return state;
}
}
```
This reveals that if no action matched the previous state is returned.