forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducer.js
50 lines (47 loc) · 941 Bytes
/
reducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { key, TIMER_START, TIMER_CANCEL, TIMER_RESET, TIMER_END,
TIMER_DECREMENT, TIMER_START_ERROR } from './actions';
export const selectors = {
value: state => state[key].value,
status: state => state[key].status
};
const initialState = {
value: 10,
status: 'stopped'
};
export default function reducer(state = initialState, action) {
switch(action.type) {
case TIMER_START:
return {
...state,
status: 'started'
};
case TIMER_CANCEL:
return {
...state,
status: 'stopped'
};
case TIMER_RESET:
return {
...state,
status: 'stopped',
value: 10
};
case TIMER_END:
return {
...state,
status: 'ended'
};
case TIMER_DECREMENT:
return {
...state,
value: state.value - 1
};
case TIMER_START_ERROR:
return {
...state,
status: action.payload.message
};
default:
return state;
}
}