yohoCoinReducer.js
3.48 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
'use strict';
import InitialState from './yohoCoinInitialState';
import Immutable, {Map} from 'immutable';
const {
GET_YOHO_COIN_NUM_REQUEST,
GET_YOHO_COIN_NUM_SUCCESS,
GET_YOHO_COIN_NUM_FAILURE,
GET_BANNER_REQUEST,
GET_BANNER_SUCCESS,
GET_BANNER_FAILURE,
GET_WEIXIN_REQUEST,
GET_WEIXIN_SUCCESS,
GET_WEIXIN_FAILURE,
BOY_GIRL_FAVORITE_REQUEST,
BOY_GIRL_FAVORITE_SUCCESS,
BOY_GIRL_FAVORITE_FAILURE,
KIDS_FAVORITE_REQUEST,
KIDS_FAVORITE_SUCCESS,
KIDS_FAVORITE_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case GET_YOHO_COIN_NUM_REQUEST: {
return state.setIn(['yohoCoin', 'isFetching'], true);
}
case GET_YOHO_COIN_NUM_SUCCESS: {
return state.setIn(['yohoCoin', 'yohocoin_num'], action.payload.yohocoin_num)
.setIn(['yohoCoin', 'notice'], action.payload.notice)
.setIn(['yohoCoin', 'isFetching'], false);
}
case GET_YOHO_COIN_NUM_FAILURE: {
return state.setIn(['yohoCoin', 'isFetching'], false)
.setIn(['yohoCoin', 'error'], action.payload);
}
case GET_BANNER_REQUEST: {
return state.setIn(['banner', 'isFetching'], true);
}
case GET_BANNER_SUCCESS: {
return state.setIn(['banner', 'list'], Immutable.fromJS(action.payload))
.setIn(['banner', 'isFetching'], false);
}
case GET_BANNER_FAILURE: {
return state.setIn(['banner', 'isFetching'], false)
.setIn(['banner', 'error'], action.payload);
}
case GET_WEIXIN_REQUEST: {
return state.setIn(['weixin', 'isFetching'], true)
.setIn(['weixin', 'error'], null);
}
case GET_WEIXIN_SUCCESS: {
return state.setIn(['weixin', 'isFetching'], false)
.setIn(['weixin', 'error'], null)
.setIn(['weixin', 'data'], Immutable.fromJS(action.payload));
}
case GET_WEIXIN_FAILURE: {
return state.setIn(['weixin', 'isFetching'], false)
.setIn(['weixin', 'error'], action.payload);
}
case BOY_GIRL_FAVORITE_REQUEST: {
return state.setIn(['favorite', 'isFetching'], true)
.setIn(['favorite', 'error'], null);
}
case BOY_GIRL_FAVORITE_SUCCESS: {
return state.setIn(['favorite', 'isFetching'], false)
.setIn(['favorite', 'error'], null)
.setIn(['favorite', 'currentPage'], action.payload.currentPage)
.setIn(['favorite', 'endReached'], action.payload.endReached)
.setIn(['favorite', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['favorite', 'pageCount'], action.payload.pageCount)
.setIn(['favorite', 'rec_id'], action.payload.rec_id)
.setIn(['favorite', 'total'], action.payload.total)
}
case BOY_GIRL_FAVORITE_FAILURE: {
return state.setIn(['favorite', 'isFetching'], false)
.setIn(['favorite', 'error'], action.payload);
}
case KIDS_FAVORITE_REQUEST: {
return state.setIn(['favorite', 'isFetching'], true)
.setIn(['favorite', 'error'], null);
}
case KIDS_FAVORITE_SUCCESS: {
return state.setIn(['favorite', 'isFetching'], false)
.setIn(['favorite', 'error'], null)
.setIn(['favorite', 'currentPage'], action.payload.currentPage)
.setIn(['favorite', 'endReached'], action.payload.endReached)
.setIn(['favorite', 'list'], Immutable.fromJS(action.payload.list))
.setIn(['favorite', 'pageCount'], action.payload.pageCount)
.setIn(['favorite', 'rec_id'], '')
.setIn(['favorite', 'total'], action.payload.total)
}
case KIDS_FAVORITE_FAILURE: {
return state.setIn(['favorite', 'isFetching'], false)
.setIn(['favorite', 'error'], action.payload);
}
}
return state;
}