userReducer.js
1.68 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
'use strict'
import InitialState from './userInitialState';
import Immutable, {List, Record} from 'immutable';
const {
USER_BACKGROUND_TAP,
USER_POSTS_REQUEST,
USER_POSTS_SUCCESS,
USER_POSTS_FAILURE,
USER_LIKE_REQUEST,
USER_LIKE_SUCCESS,
USER_LIKE_FAILURE,
USER_REPLY_REQUEST,
USER_REPLY_SUCCESS,
USER_REPLY_FAILURE,
USER_GO_TO_SETTING_STATS,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function user(state = initialState, action) {
if (!(state instanceof InitialState)) {
return initialState.merge(state);
}
switch (action.type) {
case USER_BACKGROUND_TAP:
{
// let nextState = state.set
}
break;
case USER_POSTS_REQUEST: {
let nextState = state.set('isFetching', true).set('error', null);
return nextState;
}
case USER_POSTS_SUCCESS:
{
// let nextState = state.set
let posts = state.posts;
let jsonData = posts.jsonData;
let origin = jsonData.toJS();
let {list} = action.payload;
let data = [...origin, ...(list || [])];
let nextState = state.set('isFetching', false)
.setIn(['posts','jsonData'], Immutable.fromJS(data));
return nextState;
}
break;
case USER_POSTS_FAILURE: {
let nextState = state.set('isFetching',false)
.set('error', action.playload);
return nextState;
}
case USER_GO_TO_SETTING_STATS:
return state;
default:
}
return state;
}