DiscountProductReducer.js 990 Bytes
'use strict';

import InitialState from "./DiscountProductInitialState";
import Immutable from "immutable";

const {
    QUERY_DISCOUNT_PRODUCT_LIST_REQUEST,
    QUERY_DISCOUNT_PRODUCT_LIST_SUCCESS,
    QUERY_DISCOUNT_PRODUCT_LIST_FAILURE,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function DiscountProductReducer(state = initialState, action) {
    switch (action.type) {
        case QUERY_DISCOUNT_PRODUCT_LIST_FAILURE: {
            return state.set('isFetching', false);
        }
        case QUERY_DISCOUNT_PRODUCT_LIST_SUCCESS: {
            let json = action.payload;
            return state.set('isFetching', false)
                .set('list', json.list)
                .set('currentPage', json.currentPage)
                .set('endReached', json.endReached);
        }
        case QUERY_DISCOUNT_PRODUCT_LIST_REQUEST: {
            return state.set('isFetching', true);
        }

    }

    return state;
}