Created
September 25, 2018 03:28
-
-
Save joeljameswatson/876005477b3033604c46a8a85d1a6b81 to your computer and use it in GitHub Desktop.
redux combineReducers function implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineReducers = reducers => { | |
return (state = {}, action) => { | |
// Reduce all the keys for reducers from `todos` and `visibilityFilter` | |
return Object.keys(reducers).reduce( | |
(nextState, key) => { | |
// Call the corresponding reducer function for a given key | |
nextState[key] = reducers[key] ( | |
state[key], | |
action | |
); | |
return nextState; | |
}, | |
{} // The `reduce` on our keys gradually fills this empty object until it is returned. | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment