categoryBReducer.js
1.97 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
'use strict';
import InitialStateB from './categoryBInitialState';
import Immutable, {Map} from 'immutable';
const {
GET_CATEGORY_B_LIST_REQUEST,
GET_CATEGORY_B_LIST_SUCCESS,
GET_CATEGORY_B_LIST_FAILURE,
GET_CATEGORY_B_SUBDETAIL_REQUEST,
GET_CATEGORY_B_SUBDETAIL_SUCCESS,
GET_CATEGORY_B_SUBDETAIL_FAILURE,
SET_CURRENT_CATEGORY_B,
SET_CURRENT_CHANNEL_B,
SET_CURRENT_CATEGORY_B_SUBDETAIL_FROM_CACHE,
JUMP_TO_CATEGORY,
} = require('../../constants/actionTypes').default;
const initialStateB = new InitialStateB;
export default function categoryBReducer(state=initialStateB, action) {
switch(action.type) {
case GET_CATEGORY_B_LIST_REQUEST: {
return state.set('isFetching', true)
.set('categoryError', null);
}
case GET_CATEGORY_B_LIST_SUCCESS:{
return state.set('categoryList', Immutable.fromJS(action.payload))
.set('isFetching', false)
.set('categoryError', null);
}
case GET_CATEGORY_B_LIST_FAILURE: {
return state.set('isFetching', false)
.set('categoryError', action.payload);
}
case GET_CATEGORY_B_SUBDETAIL_REQUEST: {
return state.set('contentFetching', true);
}
case GET_CATEGORY_B_SUBDETAIL_SUCCESS:{
let {key, data} = action.payload;
return state.set('contentFetching', false)
.set('currentSubCateData', Immutable.fromJS(data))
.setIn(['cacheSubCateData', key], Immutable.fromJS(data));
}
case GET_CATEGORY_B_SUBDETAIL_FAILURE: {
return state.set('contentFetching', false);
}
case SET_CURRENT_CATEGORY_B:{
return state.set('currentCateId',action.payload.id)
.set('currentCateValue',action.payload.value)
.set('currentSubCateData',Map());
}
case SET_CURRENT_CHANNEL_B:{
return state.set('currentChannelId',action.payload.id)
.set('currentChannelValue', action.payload.value);
}
case SET_CURRENT_CATEGORY_B_SUBDETAIL_FROM_CACHE: {
return state.set('contentFetching', false)
.set('currentSubCateData', Immutable.fromJS(action.payload));
}
}
return state;
}