messageReducer.js
1.11 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
'use strict';
import InitialState from './messageInitialState';
import Immutable, {Map} from 'immutable';
const {
LIKE_MESSAGE_REQUEST,
LIKE_MESSAGE_SUCCESS,
LIKE_MESSAGE_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 LIKE_MESSAGE_REQUEST: {
let nextState = state.setIn(['like', 'isFetching'], true)
.setIn(['like', 'error'], null);
return nextState;
}
case LIKE_MESSAGE_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 LIKE_MESSAGE_FAILURE:
return state.setIn(['like', 'isFetching'], false)
.setIn(['like', 'error'], action.payload);
}
return state;
}