1090100
目录 · 5 个章节
主页 https://github.com/magicdawn/redux-standard-reducer 简单点就是这么一个思想:
- 不根据 action 的类型, 去实现 reducer 去改变 state,
- 而是加一个 standard reducer, 然后在 action 加一个标识, 我这里加的 standard:true , 根据 action.payload 合并到 state, 由 action 来决定 state 的样子, 而不是reducer.
喜欢请 star, 有想法可以交流下. 个人愚见, 不对请指正. 😂
--------------下面是 README-----------
redux-standard-reducer
A redux reducer for standard action that merge data to state
Install
$ npm i redux-standard-reducer --save
Usage
// 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)
Action
action = {
type,
payload,
standard,
}
| key | type | remark |
|---|---|---|
type | String | if type starts with STANDARD_MERGE_STATE, the action payload will be merged to state |
payload | Object | the data need to be merged |
standard | Boolean | if action.standard is true, the action payload will be merged to state |
more see the test/simple.js
Changelog
License
the MIT License http://magicdawn.mit-license.org