
正文
[Redux] Implementing combineReducers() from Scratch
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
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;
}, {})
}
};


![【电子书】[教材辅导] 《Scratch少儿趣味编程》[全扫描本PDF] 【电子书】[教材辅导] 《Scratch少儿趣味编程》[全扫描本PDF]](https://www.04ip.com/template/qe/style/noimg/18.jpg)


