forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
41 lines (38 loc) · 925 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
import { key, USERS_FETCH, USERS_FETCH_CANCEL, USERS_FETCH_FULFILLED,
USERS_FETCH_REJECTED } from './actions';
export const selectors = {
users: state => state[key].list,
fetchStatus: state => state[key].fetchStatus
};
const initialState = {
list: [],
fetchStatus: ''
};
export default function reducer(state = initialState, action) {
switch(action.type) {
case USERS_FETCH:
return {
...state,
fetchStatus: `fetching... ${(new Date()).toLocaleString()}`,
list: []
};
case USERS_FETCH_FULFILLED:
return {
...state,
list: action.payload,
fetchStatus: `Results from ${(new Date()).toLocaleString()}`
};
case USERS_FETCH_REJECTED:
return {
...state,
fetchStatus: `errored: ${action.payload}`
};
case USERS_FETCH_CANCEL:
return {
...state,
fetchStatus: 'user cancelled'
};
default:
return state;
}
}