interestReducer.js
2.1 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
'use strict';
import InitialState from './interestInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_TYPE,
RESET_LIST_PAGE_INFO,
SHOW_LOGIN_TIP,
INTEREST_LIST_REQUEST,
INTEREST_LIST_SUCCESS,
INTEREST_LIST_FAILURE,
INTEREST_LIKE_STATE_CHANGE,
INTEREST_LIKE_REQUEST,
INTEREST_LIKE_SUCCESS,
INTEREST_LIKE_FAILURE,
INTEREST_LIKE_TIP_REMOVE,
LOAD_CACHED_INTEREST_LIST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function interestReducer(state=initialState, action) {
switch(action.type) {
case SET_TYPE: {
return state.set('type', action.payload);
}
case RESET_LIST_PAGE_INFO: {
return state.set('currentPage', 0)
.set('pageCount', 0)
.set('total', 0)
.set('endReached', false)
.set('addLikeTip', '');
}
case SHOW_LOGIN_TIP: {
return state.set('showLoginTip', action.payload);
}
case INTEREST_LIST_REQUEST: {
return state.set('isFetching', true)
.set('error', null)
.set('ptr', action.payload);
}
case INTEREST_LIST_SUCCESS: {
let {
list,
currentPage,
pageCount,
total,
endReached,
} = action.payload;
let newState = state.set('isFetching', false)
.set('error', null)
.set('ptr', false)
.set('list', Immutable.fromJS(list))
.set('currentPage', currentPage)
.set('pageCount', pageCount)
.set('total', total)
.set('endReached', endReached);
return newState;
}
case INTEREST_LIST_FAILURE: {
return state.set('isFetching', false)
.set('error', action.payload)
.set('ptr', false);
}
case INTEREST_LIKE_STATE_CHANGE: {
let {like, index} = action.payload;
return state.setIn(['list', index, 'is_fav'], like)
.set('addLikeTip', '收藏成功');
}
case INTEREST_LIKE_TIP_REMOVE: {
return state.set('addLikeTip', '');
}
case INTEREST_LIKE_REQUEST:
case INTEREST_LIKE_SUCCESS:
case INTEREST_LIKE_FAILURE: {
return state;
}
case LOAD_CACHED_INTEREST_LIST: {
return state.set('cachedList', Immutable.fromJS(action.payload));
}
}
return state;
}