homeReducer.js
2.26 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
import InitialState from './homeInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_CHANNEL,
GET_GLOBAL_HOME_RESOURCE_REQUEST,
GET_GLOBAL_HOME_RESOURCE_SUCCESS,
GET_GLOBAL_HOME_RESOURCE_FAILURE,
GET_GLOBAL_PRODUCT_LIST_REQUEST,
GET_GLOBAL_PRODUCT_LIST_SUCCESS,
GET_GLOBAL_PRODUCT_LIST_FAILURE,
SET_FLITER,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function homeReducer(state=initialState, action) {
switch(action.type) {
case GET_GLOBAL_HOME_RESOURCE_REQUEST:
{
return state.set('isFetching', true)
.set('error', null)
.set('ptr', action.payload);
}
break;
case GET_GLOBAL_HOME_RESOURCE_SUCCESS:
{
let {
list,
page,
total,
total_page,
content_code,
groupInfo,
} = action.payload;
let newState = state.set('isFetching', false)
.set('error', null)
.set('ptr', false)
.set('list', Immutable.fromJS(list))
.set('content_code', content_code)
.set('total_page', total_page)
.set('total', total)
.setIn(['groupInfo', 'list'], Immutable.fromJS(groupInfo))
return newState;
}
break;
case GET_GLOBAL_HOME_RESOURCE_FAILURE:
{
return state.set('isFetching', false)
.set('error', action.payload)
.set('ptr', false);
}
break;
case GET_GLOBAL_PRODUCT_LIST_REQUEST:
{
let {
isFetching,
page,
filter,
endReached,
} = action.payload;
let list = state.groupInfo.list.toJS();
list[filter].isFetching = isFetching;
list[filter].fliter = filter;
list[filter].page = page;
list[filter].endReached = endReached;
return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
}
break;
case GET_GLOBAL_PRODUCT_LIST_SUCCESS:
{
let newState = state.setIn(['groupInfo', 'list'], Immutable.fromJS(action.payload));
return newState;
}
break;
case GET_GLOBAL_PRODUCT_LIST_FAILURE:
{
let list = state.groupInfo.list.toJS();
list[0].isFetching = false;
list[0].page = list[0].page - 1;
list[0].error = error;
return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
}
break;
case SET_FLITER:
{
let newState = state.setIn(['groupInfo', 'fliter'], action.payload);
return newState;
}
break;
}
return state;
}