appReducer.js
4.32 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
106
107
108
109
110
111
112
113
114
115
116
'use strict';
import InitialState from './appInitialState';
import Immutable, {List} from "immutable";
const {
SET_PLATFORM,
SET_CHANNEL,
SET_HOST,
SET_SERVICE_HOST,
SET_PRODUCT_POOL,
SET_SKNS,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
APP_SET_SELECTED_CATEGORY,
BANNER_INVITECODE_REQUEST,
BANNER_INVITECODE_SUCCESS,
BANNER_INVITECODE_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function appReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case SET_PLATFORM:
return state.set('platform', action.payload);
case SET_CHANNEL:
return state.set('channel', action.payload);
case SET_HOST:
return state.set('host', action.payload);
case SET_SERVICE_HOST:
return state.set('serviceHost', action.payload);
case SET_PRODUCT_POOL: {
return state.set('productPool', action.payload);
}
case SET_SKNS: {
return state.set('skns', action.payload);
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
page,
page_total,
endReached,
product_list,
msort_list,
} = action.payload;
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'page'], page)
.setIn(['productList', 'page_total'], page_total)
.setIn(['productList', 'endReached'], endReached)
.setIn(['productList', 'product_list'], Immutable.fromJS(product_list))
.setIn(['productList', 'msort_list'], msort_list ? Immutable.fromJS(msort_list): state.get('productList').get('msort_list'))
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
case APP_SET_SELECTED_CATEGORY: {
let {index, sort_id, sort_name} = action.payload;
return state
.setIn(['productList', 'current_sort_name'], sort_name)
.setIn(['productList', 'current_sort_id'], sort_id)
.setIn(['productList', 'selectedCategoryIndex'], index)
.setIn(['productList', 'page'], 0)
// .setIn(['productList', 'product_list'], List())
.setIn(['productList', 'page_total'], 0)
.setIn(['productList', 'endReached'], false)
.setIn(['productList', 'error'], null);
}
case BANNER_INVITECODE_REQUEST: {
return state.setIn(['inviteCode', 'isFetching'], true)
.setIn(['inviteCode', 'error'], null)
}
case BANNER_INVITECODE_SUCCESS: {
let {
context,
myCouponNum,
shareMainTitle,
shareSubTitle,
totalCouponNum,
totalUser,
url,
userInviteTotal,
} = action.payload;
return state.setIn(['inviteCode', 'isFetching'], false)
.setIn(['inviteCode', 'context'], context ? context : {})
.setIn(['inviteCode', 'myCouponNum'], myCouponNum)
.setIn(['inviteCode', 'shareMainTitle'], shareMainTitle ? Immutable.fromJS(shareMainTitle) : {})
.setIn(['inviteCode', 'shareSubTitle'], shareSubTitle ? Immutable.fromJS(shareSubTitle) : {})
.setIn(['inviteCode', 'totalCouponNum'], totalCouponNum)
.setIn(['inviteCode', 'totalUser'], totalUser)
.setIn(['inviteCode', 'url'], url)
.setIn(['inviteCode', 'userInviteTotal'], userInviteTotal)
}
case BANNER_INVITECODE_FAILURE: {
return state.setIn(['inviteCode', 'isFetching'], false)
.setIn(['inviteCode', 'error'], action.payload ? action.payload: null)
}
}
return state;
}