messageReducer.js
4.27 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
'use strict';
import InitialState from './messageInitialState';
import Immutable, {Map, List, Record} from 'immutable';
const {
GO_TO_SYS_MESSAGE,
GO_TO_LIKE_MESSAGE,
MESSAGE_INFO_REQUEST,
MESSAGE_INFO_SUCCESS,
MESSAGE_INFO_FAILURE,
MESSAGE_CENTER_REQUEST,
MESSAGE_CENTER_SUCCESS,
MESSAGE_CENTER_FAILURE,
MESSAGE_LIKE_REQUEST,
MESSAGE_LIKE_SUCCESS,
MESSAGE_LIKE_FAILURE,
MESSAGE_SYST_REQUEST,
MESSAGE_SYST_SUCCESS,
MESSAGE_SYST_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function message(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case MESSAGE_LIKE_REQUEST: {
let nextState = state.setIn(['like', 'isFetching'], true)
.setIn(['like', 'error'], null);
return nextState;
}
case MESSAGE_LIKE_SUCCESS: {
let {lastedTime, list, endReached} = action.payload;
let nextState = state.setIn(['like', 'isFetching'], false)
.setIn(['like', 'error'], null)
.setIn(['like', 'lastedTime'], lastedTime)
.setIn(['like', 'endReached'], endReached)
.setIn(['like', 'list'], Immutable.fromJS(list));
return nextState;
}
case MESSAGE_LIKE_FAILURE:
return state.setIn(['like', 'isFetching'], false)
.setIn(['like', 'error'], action.payload);
case MESSAGE_INFO_REQUEST:
{
let nextState = state.setIn(['centerMsg', 'error'], null)
.setIn(['centerMsg', 'ptr'], action.payload)
.setIn(['centerMsg', 'isFetching'], true);
return nextState;
}
break;
case MESSAGE_INFO_SUCCESS:
{
let nextState = state.setIn(['centerMsg', 'sysMsg'], action.payload.sysMsg)
.setIn(['centerMsg', 'likeMsg'], action.payload.likeMsg)
.setIn(['centerMsg', 'isFetching'], false);
return nextState;
}
break;
case MESSAGE_INFO_FAILURE:
{
let nextState = state.setIn(['centerMsg', 'error'], action.payload)
.setIn(['centerMsg', 'isFetching'], false);
return nextState;
}
break;
case MESSAGE_CENTER_REQUEST:
{
let nextState = state.setIn(['centerMsg', 'isFetching'], true)
.setIn(['centerMsg', 'error'], null);
return nextState;
}
break;
case MESSAGE_CENTER_SUCCESS:
{
let {lastedTime, list, endReached} = action.payload;
let nextState = state.setIn(['centerMsg', 'isFetching'], false)
.setIn(['centerMsg', 'error'], null)
.setIn(['centerMsg', 'lastedTime'], lastedTime)
.setIn(['centerMsg', 'endReached'], endReached)
.setIn(['centerMsg', 'list'], Immutable.fromJS(list))
.setIn(['centerMsg', 'ptr'], false);
return nextState;
}
break;
case MESSAGE_CENTER_FAILURE:
{
return state.setIn(['centerMsg', 'isFetching'], false)
.setIn(['centerMsg', 'error'], action.payload);
}
break;
case MESSAGE_SYST_REQUEST:
{
let nextState = state.setIn(['system', 'isFetching'], true)
.setIn(['system', 'error'], null);
return nextState;
}
break;
case MESSAGE_SYST_SUCCESS:
{
let {lastedTime, list, endReached} = action.payload;
let nextState = state.setIn(['system', 'isFetching'], false)
.setIn(['system', 'error'], null)
.setIn(['system', 'lastedTime'], lastedTime)
.setIn(['system', 'endReached'], endReached)
.setIn(['system', 'list'], Immutable.fromJS(list))
.setIn(['system', 'ptr'], false);
return nextState;
}
break;
case MESSAGE_SYST_FAILURE:
{
return state.setIn(['system', 'isFetching'], false)
.setIn(['system', 'error'], action.payload);
}
break;
default:
}
return state;
}