cardListReducer.js 956 Bytes
'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);
        case GET_CARD_LIST_FAILURE:
            return state.set('isFetching', false);
        case GET_CARD_LIST_SUCCESS:
            return state.set('isFetching', false)
                        .set('cardList', Immutable.fromJS(action.payload));

    }

    return state;
}