messageReducer.js
2.38 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
'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;
default:
}
return state;
}