Skip to content

Instantly share code, notes, and snippets.

@eduardomoroni
Created June 26, 2018 18:53
Show Gist options
  • Save eduardomoroni/ced73c30303b47b5a3219603b0f6951a to your computer and use it in GitHub Desktop.
Save eduardomoroni/ced73c30303b47b5a3219603b0f6951a to your computer and use it in GitHub Desktop.
Counter Reducer
// 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