Skip to content

Instantly share code, notes, and snippets.

@evgenyfedorenko
Created November 11, 2019 20:49
Show Gist options
  • Save evgenyfedorenko/21e131426e39a842eb603d545ffba9b2 to your computer and use it in GitHub Desktop.
Save evgenyfedorenko/21e131426e39a842eb603d545ffba9b2 to your computer and use it in GitHub Desktop.
function reducerFactory(reducers) {
return function combination(state, action) {
const nextState: any = {};
const reducerKeys = Object.keys(reducers);
for (let i = 0; i < reducerKeys.length; i++) {
const key = reducerKeys[i];
const reducer: any = reducers[key];
nextState[key] = reducer(state[key], action);
}
return nextState;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment