shareDetailReducer.js 1.56 KB
'use strict';

import InitialState from './shareDetailInitialState';
import Immutable, {List} from "immutable";

const {
    SHARE_DETAIL_REQUEST,
    SHARE_DETAIL_SUCCESS,
    SHARE_DETAIL_FAILURE,
    ADD_FAVORITE_REQUEST,
    ADD_FAVORITE_SUCCESS,
    ADD_FAVORITE_FAILURE,
    FAVORITE_INFO_REQUEST,
    FAVORITE_INFO_FAILURE,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function appReducer(state = initialState, action) {
    if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {
        case SHARE_DETAIL_REQUEST:
            return state.set('isFetching', true);
        case SHARE_DETAIL_SUCCESS:
            return state.set('isFetching', false)
            .set('productInfo', Immutable.fromJS(action.payload));
        case SHARE_DETAIL_FAILURE:
            return state.set('isFetching', false)
                    .set('error', action.payload);
        case ADD_FAVORITE_REQUEST:
            return state.set('isFetching', true);
        case ADD_FAVORITE_SUCCESS:
            return state.set('isFetching', false)
            .set('isCollect', action.payload);
        case ADD_FAVORITE_FAILURE:
            return state.set('isFetching', false)
            .set('error', action.payload);
        case ADD_FAVORITE_FAILURE:
            return state.set('isFetching', false)
            .set('error', action.payload);
        case ADD_FAVORITE_FAILURE:
            return state.set('isFetching', false)
            .set('error', action.payload);
    }

    return state;
}