Created
October 6, 2017 14:00
-
-
Save ghetolay/5c3dea9e36ac553a1974509d3bfb722b to your computer and use it in GitHub Desktop.
Ngrx reducer as map
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 IncrementAction = ...; | |
const DecrementAction = ...; | |
const reducer1 = { | |
[]: () => 0, | |
[IncrementAction.type]: (state, action) => state + 1, | |
[DecrementAction.type]: (state, action) => state - 1 | |
}; | |
const reducers: { [type: string]: ReduceFn[] } = merge(reducer1, reducer2, ...); | |
function dispatch(action: Action){ | |
const newState = reducers[action]?.reduce( (state, reducer) => reducer(state, action), currentState ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment