Home

Redux combineReducers js 作者简单实现

来源 Redux作者入门教程

combineReducers

js 简单实现

const combineReducers = (reducers) =>{
    return (state = {}, action) =>{
        return Object.Keys(reducers).reduce(

            (nextState, key) =>{

                nextState[key] = reducers[key](
                    state[key], 
                    action
                );
                return nextState;

            }, {})
    };
};