Skip to content

Instantly share code, notes, and snippets.

@cjoecker
Last active March 28, 2020 19:45
Show Gist options
  • Save cjoecker/38ef4c425f35132cbf5f35895515fb0a to your computer and use it in GitHub Desktop.
Save cjoecker/38ef4c425f35132cbf5f35895515fb0a to your computer and use it in GitHub Desktop.
Counter_Reducer.ts
import {Reducer} from "redux";
import {DispatchAction} from "./store";
import {CounterActionTypes} from "./Counter_Actions";
export class CounterState {
counterNumber: number = 0;
}
export const Counter_Reducer: Reducer<CounterState, DispatchAction> = (state = new CounterState(), action) => {
switch (action.type) {
case CounterActionTypes.SumCounter:
return {
...state,
counterNumber: state.counterNumber + 1,
};
case CounterActionTypes.SubtractCounter:
return {
...state,
counterNumber: state.counterNumber - 1,
};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment