老师,请问 两个reducer ,是怎么分别和自己的state 联系在一起的。
来源:4-11 react-router4 路由 04-和 Redux 配合-复杂 Redux 应用2

qq_樱花树下的羁绊_0
2017-11-22
const rooterReducer = combineReducers({counter, logReducer}); 这里没有传递state,是怎么分别对应上的
写回答
1回答
-
其实就是用对象管理的,直接看 redux 源码
for (let i = 0; i < finalReducerKeys.length; i++) { const key = finalReducerKeys[i] const reducer = finalReducers[key] const previousStateForKey = state[key] const nextStateForKey = reducer(previousStateForKey, action) if (typeof nextStateForKey === 'undefined') { const errorMessage = getUndefinedStateErrorMessage(key, action) throw new Error(errorMessage) } nextState[key] = nextStateForKey hasChanged = hasChanged || nextStateForKey !== previousStateForKey }
dispatch执行 reducers 时,根据 reducers 的名字,传入不同的 state
022017-11-27
Redux+React Router+Node.js全栈开发
全网唯一的React 16+Redux+React Router4实战课程,学到手是你的真本领!
1822 学习 · 750 问题
相似问题
装饰器问题
回答 1
有一个报错函数不明白怎么用的
回答 2