Answer1215

The combineReducers function we used in previous post:

const todoApp = combineReducers({
  todos,
  visibilityFilter
});

 

  • It accepts and object as agruement;
  • It returns an function

 

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;
    }, {})
  }
};

 

分类:

技术点:

相关文章:

  • 2021-07-01
  • 2021-09-07
  • 2021-11-15
  • 2021-10-17
  • 2021-09-02
  • 2022-01-01
  • 2021-08-12
  • 2022-02-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案