Created
September 17, 2019 09:34
-
-
Save velosipedist/bd97ff5ac26479ca36878c1fa1a63eb7 to your computer and use it in GitHub Desktop.
Simplified reduce-reducers version, without any extra arguments supported
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
const rootReducer = (...reducers) => { | |
return (stateInit, action) => { | |
return reducers.reduce( | |
(state, reducer, at) => { | |
return reducer(state, action) || state | |
}, | |
stateInit | |
); | |
} | |
}; | |
// works like this | |
//... somewhere at React Redux initiation | |
const rootStorage = createStore(rootReducer(...[ | |
reduceFunctionOne, | |
reduceFunctionTwo// ,... | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment