Reducer Composition with combineReducers()
Redux has a
combineReducers
method to simplify the reducer composition pattern:
const { combineReducers } = Redux;
const todoApp = combineReducers({
todos: todos,
visibilityFilter: visibilityFilter
});
// ----- can now delete this
// const todoApp = (state={}, action) => {
// return {
// todos: todos(state.todos, action),
// visibilityFilter: visibilityFilter(state.visibilityFilter, action)
// };
// }
You just have to map the state field names and the reducers managing them. If we always name the reducers the same way as the keys the manage we can simplify the syntax (ES6 object literal shorthand notation):
const todoApp = combineReducers({todos, visibilityFilter});