shareDetailReducer.js
3.02 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
'use strict';
import InitialState from './shareDetailInitialState';
import Immutable, {List} from "immutable";
const {
SHARE_DETAIL_REQUEST,
SHARE_DETAIL_SUCCESS,
SHARE_DETAIL_FAILURE,
ADD_FAVORITE_REQUEST,
ADD_FAVORITE_SUCCESS,
ADD_FAVORITE_FAILURE,
FAVORITE_INFO_REQUEST,
FAVORITE_INFO_FAILURE,
SHARE_CODE_INFO_REQUEST,
SHARE_CODE_INFO_SUCCESS,
SHARE_CODE_INFO_FAILURE,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_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 SHARE_DETAIL_REQUEST:
return state.set('isFetching', true);
case SHARE_DETAIL_SUCCESS:
return state.set('isFetching', false)
.set('productInfo', Immutable.fromJS(action.payload));
case SHARE_DETAIL_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_REQUEST:
return state.set('isFetching', true);
case ADD_FAVORITE_SUCCESS:
return state.set('isFetching', false)
.set('isCollect', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case SHARE_CODE_INFO_REQUEST:
return state.set('isFetching', true);
case SHARE_CODE_INFO_SUCCESS:
return state.set('isFetching', false)
.set('shareCodeInfo', Immutable.fromJS(action.payload));
case SHARE_CODE_INFO_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
product_list,
page,
page_total,
total,
endReached,
} = action.payload;
return state.setIn(['productList', 'page'], page)
.setIn(['productList', 'pagetotal'], page_total)
.setIn(['productList', 'total'], total)
.setIn(['productList', 'product_list'], Immutable.fromJS(product_list))
.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'endReached'], endReached);
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
}
return state;
}