Reducer Composition with combineReducers()

In notebook:
Egghead Redux
Created at:
2016-07-09
Updated:
2016-07-10
Tags:
pattern libraries JavaScript
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});