https://github.com/magicdawn/redux-standard-reducer
A redux reducer for standard action that merge data to state
https://github.com/magicdawn/redux-standard-reducer
Last synced: 3 months ago
JSON representation
A redux reducer for standard action that merge data to state
- Host: GitHub
- URL: https://github.com/magicdawn/redux-standard-reducer
- Owner: magicdawn
- License: mit
- Created: 2017-08-20T13:08:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-06T16:05:37.000Z (almost 9 years ago)
- Last Synced: 2025-01-15T13:49:26.183Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-standard-reducer
> A redux reducer for standard action that merge data to state
[](https://travis-ci.org/magicdawn/redux-standard-reducer)
[](https://codecov.io/gh/magicdawn/redux-standard-reducer)
[](https://www.npmjs.com/package/redux-standard-reducer)
[](https://www.npmjs.com/package/redux-standard-reducer)
[](http://magicdawn.mit-license.org)
## Install
```sh
$ npm i redux-standard-reducer --save
```
## Usage
```js
// suppose all business reducer exits in app/reducers/
import reducer from './app/reducers'
import standardReducer from 'redux-standard-reducer'
import reduceReducers from 'reduce-reducers'
// reducer for createStore
const finalReducer = reduceReducers(
standardReducer,
reducer
)
const store = createStore(initialState, finalReducer, enhancers)
```
### enable this reducer
use any one of these:
- make `action.type` starts with `STANDARD_MERGE_STATE`, this reducer will handle the action
- make `action.standard = true`, this reducer will handle the action
### Action with `payload`
```js
action = {
type,
standard,
payload: {...},
}
```
|key |type |remark|
|-----------|-----------|------|
| `payload` | `Object` | the data need to be merged to the `store.state` |
- more see the [test/simple.js](test/simple.js)
### Action with `update`
```js
action = {
type,
standard,
update: {...},
}
```
|key |type |remark|
|-----------|-----------|------|
| `update` | `Object` | the `update` operation, will pass to [immutability-helper](https://github.com/kolodny/immutability-helper#update), equal to `immutabilityHelper(store.state, action.update)` |
- more see the [test/simple.js](test/update.js)
- see `update` in [immutability-helper](https://github.com/kolodny/immutability-helper#update) homepage
## Changelog
[CHANGELOG.md](CHANGELOG.md)
## License
the MIT License http://magicdawn.mit-license.org