Skip to content

Instantly share code, notes, and snippets.

@AustinMatherne
Created September 29, 2017 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AustinMatherne/b5f528e2091ca0192044a9d4051665e2 to your computer and use it in GitHub Desktop.
Save AustinMatherne/b5f528e2091ca0192044a9d4051665e2 to your computer and use it in GitHub Desktop.
String Enum Typed Reducer
// 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