detailReducer.js
4.18 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
import InitialState from './detailInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ARTICLE_ID,
GET_ARTICLE_REQUEST,
GET_ARTICLE_SUCCESS,
GET_ARTICLE_FAILURE,
GET_AUTHOR_REQUEST,
GET_AUTHOR_SUCCESS,
GET_AUTHOR_FAILURE,
GET_ARTICLE_CONTENT_REQUEST,
GET_ARTICLE_CONTENT_SUCCESS,
GET_ARTICLE_CONTENT_FAILURE,
GET_BRAND_REQUEST,
GET_BRAND_SUCCESS,
GET_BRAND_FAILURE,
GET_OTHER_ARTICLE_REQUEST,
GET_OTHER_ARTICLE_SUCCESS,
GET_OTHER_ARTICLE_FAILURE,
GET_WEIXIN_PUBLIC_REQUEST,
GET_WEIXIN_PUBLIC_SUCCESS,
GET_WEIXIN_PUBLIC_FAILURE,
PRODUCT_BY_SKNS_SUCCESS,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function detailReducer(state=initialState, action) {
switch(action.type) {
case SET_ARTICLE_ID: {
return state.set('articleId', action.payload);
}
case GET_ARTICLE_REQUEST: {
return state.setIn(['article', 'isFetching'], true)
.setIn(['article', 'error'], null);
}
case GET_ARTICLE_SUCCESS: {
return state.setIn(['article', 'isFetching'], false)
.setIn(['article', 'error'], null)
.setIn(['article', 'data'], Immutable.fromJS(action.payload));
}
case GET_ARTICLE_FAILURE: {
return state.setIn(['article', 'isFetching'], false)
.setIn(['article', 'error'], action.payload);
}
case GET_AUTHOR_REQUEST: {
return state.setIn(['author', 'isFetching'], true)
.setIn(['author', 'error'], null);
}
case GET_AUTHOR_SUCCESS: {
return state.setIn(['author', 'isFetching'], false)
.setIn(['author', 'error'], null)
.setIn(['author', 'data'], Immutable.fromJS(action.payload));
}
case GET_AUTHOR_FAILURE: {
return state.setIn(['author', 'isFetching'], false)
.setIn(['author', 'error'], action.payload);
}
case GET_ARTICLE_CONTENT_REQUEST: {
return state.setIn(['content', 'isFetching'], true)
.setIn(['content', 'error'], null);
}
case GET_ARTICLE_CONTENT_SUCCESS: {
return state.setIn(['content', 'isFetching'], false)
.setIn(['content', 'error'], null)
.setIn(['content', 'data'], Immutable.fromJS(action.payload));
}
case GET_ARTICLE_CONTENT_FAILURE: {
return state.setIn(['content', 'isFetching'], false)
.setIn(['content', 'error'], action.payload);
}
case GET_BRAND_REQUEST: {
return state.setIn(['brand', 'isFetching'], true)
.setIn(['brand', 'error'], null);
}
case GET_BRAND_SUCCESS: {
return state.setIn(['brand', 'isFetching'], false)
.setIn(['brand', 'error'], null)
.setIn(['brand', 'data'], Immutable.fromJS(action.payload));
}
case GET_BRAND_FAILURE: {
return state.setIn(['brand', 'isFetching'], false)
.setIn(['brand', 'error'], action.payload);
}
case GET_OTHER_ARTICLE_REQUEST: {
return state.setIn(['otherArticle', 'isFetching'], true)
.setIn(['otherArticle', 'error'], null);
}
case GET_OTHER_ARTICLE_SUCCESS: {
return state.setIn(['otherArticle', 'isFetching'], false)
.setIn(['otherArticle', 'error'], null)
.setIn(['otherArticle', 'data'], Immutable.fromJS(action.payload));
}
case GET_OTHER_ARTICLE_FAILURE: {
return state.setIn(['otherArticle', 'isFetching'], false)
.setIn(['otherArticle', 'error'], action.payload);
}
case GET_WEIXIN_PUBLIC_REQUEST: {
return state.setIn(['weixin', 'isFetching'], true)
.setIn(['weixin', 'error'], null);
}
case GET_WEIXIN_PUBLIC_SUCCESS: {
return state.setIn(['weixin', 'isFetching'], false)
.setIn(['weixin', 'error'], null)
.setIn(['weixin', 'data'], Immutable.fromJS(action.payload));
}
case GET_WEIXIN_PUBLIC_FAILURE: {
return state.setIn(['weixin', 'isFetching'], false)
.setIn(['weixin', 'error'], action.payload);
}
case PRODUCT_BY_SKNS_SUCCESS: {
let {
productList,
contentIndex
} = action.payload;
return state.setIn(['content', 'data', contentIndex, 'productList'], Immutable.fromJS(productList));
}
}
return state;
}