categoryReducer.js
1.3 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
'use strict';
import InitialState from './categoryInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_TYPE,
SET_CURRENT_CATEGORY_ID,
SET_CURRENT_CHANNEL_ID,
GET_CATEGORY_REQUEST,
GET_CATEGORY_SUCCESS,
GET_CATEGORY_FAILURE,
JUMP_TO_CATEGORY,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function categoryReducer(state=initialState, action) {
switch(action.type) {
case SET_TYPE: {
return state.set('type', action.payload);
}
case GET_CATEGORY_REQUEST: {
return state.set('isFetching', true);
}
case GET_CATEGORY_SUCCESS:{
let {
boy,
girl,
kids,
lifestyle,
} = action.payload;
return state.setIn(['categoryList', 'boy'],Immutable.fromJS(boy))
.setIn(['categoryList', 'girl'],Immutable.fromJS(girl))
.setIn(['categoryList', 'kids'],Immutable.fromJS(kids))
.setIn(['categoryList', 'lifestyle'],Immutable.fromJS(lifestyle))
.set('isFetching', false);
}
case GET_CATEGORY_FAILURE: {
return state.set('isFetching', false);
}
case SET_CURRENT_CATEGORY_ID:{
return state.set('currentCateId',Immutable.fromJS(action.payload));
}
case SET_CURRENT_CHANNEL_ID:{
return state.set('currentChannelId',Immutable.fromJS(action.payload));
}
}
return state;
}