ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
![](https://img.kancloud.cn/0a/d4/0ad455619299c78a87a64c894d2e61fe_792x465.png) ![](https://img.kancloud.cn/49/a2/49a2485ec2644a97b51eb1d66c1fc629_999x462.png) ~~~ export default function combineReducers(reducers){ let reducerKeys = Object.keys(reducers);//[counter1,counter2] return function (state={},action){ let hasChanged = false;//此次派发动作是否引起了状态的修改,或者说状态的改变 const nextState = {}; for(let i=0;i<reducerKeys.length;i++){ const key = reducerKeys[i];//counter1 const previousStateForKey = state[key];//{number:0} const reducer = reducers[key];//counter1 let nextStateForKey = reducer(previousStateForKey,action);//{type:'ADD1'} {number:1} nextState[key] = nextStateForKey; hasChanged = hasChanged||nextStateForKey!==previousStateForKey; } return hasChanged?nextState:state; } } ~~~ ~~~ export default function bindActionCreators(actionCreators,dispatch){ function bindActionCreator(actionCreator, dispatch){ return (...args)=>dispatch(actionCreator(...args)); } if(typeof actionCreators == 'function'){ return bindActionCreator(actionCreators,dispatch); } let boundActionCreators = {}; for(let key in actionCreators){ boundActionCreators[key] = bindActionCreator(actionCreators[key],dispatch); } return boundActionCreators; } ~~~