Skip to content

Instantly share code, notes, and snippets.

@velosipedist
Created September 17, 2019 09:34
Show Gist options
  • Save velosipedist/bd97ff5ac26479ca36878c1fa1a63eb7 to your computer and use it in GitHub Desktop.
Save velosipedist/bd97ff5ac26479ca36878c1fa1a63eb7 to your computer and use it in GitHub Desktop.
Simplified reduce-reducers version, without any extra arguments supported
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