UNPKG

899 BJavaScriptView Raw
1// @flow
2import { combineReducers } from 'redux';
3
4import type { CounterState, CounterAction } from './types';
5
6// ACTION TYPES
7const INCREMENT = 'INCREMENT';
8const DECREMENT = 'DECREMENT';
9const DUPLICATION = 'DUPLICATION';
10
11// ACTIONS
12export const increase = () => ({ type: INCREMENT });
13export const decrease = () => ({ type: DECREMENT });
14export const double = () => ({ type: DUPLICATION });
15
16// REDUCERS
17/** State Shape
18 * { counter: { value: INTEGER } }
19*/
20
21const initialState = { value: 0 };
22
23export 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
32export const reducers = combineReducers({ counter });