Created
June 26, 2018 18:53
-
-
Save eduardomoroni/ced73c30303b47b5a3219603b0f6951a to your computer and use it in GitHub Desktop.
Counter 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
// Rest of the file omitted | |
const incrementReducer = ( | |
counter: StateSliceType, | |
action: ActionType, | |
): StateSliceType => { | |
const interactor = new CounterInteractor(counter); | |
interactor.increment(action.qty); | |
return new Counter(interactor.counter.count); | |
}; | |
export const counterReducer = ( | |
state: StateSliceType = INITIAL_STATE, | |
action: ActionType, | |
): StateSliceType => { | |
switch (action.type) { | |
case INCREMENT: | |
return incrementReducer(state, action); | |
case DECREMENT: | |
return decrementReducer(state, action); | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment