Created
September 29, 2017 05:01
-
-
Save AustinMatherne/08a7841323f234e63c3a04d7d6f0da1b to your computer and use it in GitHub Desktop.
Const Typed Reducer
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
// counter.reducer.ts | |
import * as CounterActions from './counter.actions'; | |
export type Action = CounterActions.All; | |
export function reducer(state: number = 0, action: Action): State { | |
switch(action.type) { | |
case CounterActions.INCREMENT: { | |
return state + 1; | |
} | |
case CounterActions.DECREMENT: { | |
return state - 1; | |
} | |
case CounterActions.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