The combineReducers function we used in previous post:
const todoApp = combineReducers({
todos,
visibilityFilter
});
Implemente by ourself:
// reducers: {todos: todos, filter: filter} const combineReducers = (reducers) => { // return a reducer function return (state={},action)=>{ // combine the reducers return Object.keys(reducers) .reduce( (acc, curr)=>{ acc[curr] = reducers[curr]( state[curr], action ); // todos: todos return acc; }, {}) } };
[Redux] Implementing combineReducers() from Scratch
原文:http://www.cnblogs.com/Answer1215/p/5065444.html