cardListReducer.js
1.07 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
'use strict';
import InitialState from './cardListInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_ERROR,
SET_TIP_MESSAGE,
GET_CARD_LIST_REQUEST,
GET_CARD_LIST_FAILURE,
GET_CARD_LIST_SUCCESS,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function appReducer(state = initialState, action) {
switch (action.type) {
case SET_ERROR:
return state.set('error',action.payload);
case SET_TIP_MESSAGE:
return state.set('tipMessage', action.payload);
case GET_CARD_LIST_REQUEST:
return state.set('isFetching', true)
.set('error', null);
case GET_CARD_LIST_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case GET_CARD_LIST_SUCCESS:
return state.set('isFetching', false)
.set('error', null)
.set('cardList', Immutable.fromJS(action.payload));
}
return state;
}