plustarReducer.js
1.33 KB
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
51
52
53
54
55
56
57
58
59
'use strict';
import InitialState from './plustarInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_SEGMENT,
SET_GENDER,
PLUSTAR_LIST_REQUEST,
PLUSTAR_LIST_SUCCESS,
PLUSTAR_LIST_FAILURE,
SWITCH_SEGMENT,
SWITCH_GENDER,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function plustarReducer(state=initialState, action) {
switch(action.type) {
case SET_SEGMENT: {
return state.set('segment', action.payload);
}
case PLUSTAR_LIST_REQUEST: {
let key = action.payload;
return state.setIn([key, 'isFetching'], true)
.setIn([key, 'error'], null);
}
case PLUSTAR_LIST_SUCCESS: {
let {head, foot, list, key} = action.payload;
return state.setIn([key, 'isFetching'], false)
.setIn([key, 'error'], null)
.setIn([key, 'head'], Immutable.fromJS(head))
.setIn([key, 'foot'], Immutable.fromJS(foot))
.setIn([key, 'list'], Immutable.fromJS(list));
}
case PLUSTAR_LIST_FAILURE: {
let {error, key} = action.payload;
return state.setIn([key, 'isFetching'], false)
.setIn([key, 'error'], error);
}
case SWITCH_SEGMENT: {
return state.set('activeTab', action.payload);
}
case SET_GENDER:
case SWITCH_GENDER: {
return state.set('gender', action.payload);
}
}
return state;
}