Created
September 29, 2017 05:02
-
-
Save AustinMatherne/b5f528e2091ca0192044a9d4051665e2 to your computer and use it in GitHub Desktop.
String Enum Typed Reducer
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
// counter.reducer.ts | |
import { CounterActions, CounterTypes } from './counter.actions'; | |
export function reducer(state: number = 0, action: CounterActions): State { | |
switch(action.type) { | |
case CounterTypes.INCREMENT: { | |
return state + 1; | |
} | |
case CounterTypes.DECREMENT: { | |
return state - 1; | |
} | |
case CounterTypes.RESET: { | |
return action.payload; // typed to number | |
} | |
default: { | |
return state; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment