1 |
|
2 | import { combineReducers } from 'redux';
|
3 |
|
4 | import type { CounterState, CounterAction } from './types';
|
5 |
|
6 |
|
7 | const INCREMENT = 'INCREMENT';
|
8 | const DECREMENT = 'DECREMENT';
|
9 | const DUPLICATION = 'DUPLICATION';
|
10 |
|
11 |
|
12 | export const increase = () => ({ type: INCREMENT });
|
13 | export const decrease = () => ({ type: DECREMENT });
|
14 | export const double = () => ({ type: DUPLICATION });
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const initialState = { value: 0 };
|
22 |
|
23 | export const counter = (state: CounterState = initialState, action: CounterAction) => {
|
24 | switch (action.type) {
|
25 | case INCREMENT: return { ...state, value: state.value + 1 };
|
26 | case DECREMENT: return { ...state, value: state.value - 1 };
|
27 | case DUPLICATION: return { ...state, value: state.value * 2 };
|
28 | default: return state;
|
29 | }
|
30 | };
|
31 |
|
32 | export const reducers = combineReducers({ counter });
|