Last active
March 28, 2020 19:45
-
-
Save cjoecker/38ef4c425f35132cbf5f35895515fb0a to your computer and use it in GitHub Desktop.
Counter_Reducer.ts
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
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