Created
April 18, 2018 00:43
-
-
Save jagretz/b9ad029c796faf38092e403e8b6154c4 to your computer and use it in GitHub Desktop.
Reduce multiple reducer functions passing state and action through each in sequence.
This file contains hidden or 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
/** | |
* Supply multiple reducer functions, as arguments, and return a new reducer function that pipes the | |
* state and action through each reducer in sequence. | |
* @param {...functions} reducers like (arg1, arg2, ...), as a serires of arguments. | |
* @return {function} a new reducer function that pipes the state and action through each reducer in sequence. | |
* Each successive reducer will receive the updated returned by the previous reducer. | |
*/ | |
export default function reduceReducers(...reducers) { | |
return (currentState = {}, action = {}) => | |
reducers.reduce((updatedState, red) => red(updatedState, action), currentState); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment