var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import ListingActionTypes from './ListingActionTypes';
export var initialState = {
    itemCache: {},
    visibleItemIds: [],
    isLoading: false,
    loadingError: null,
    baseQueries: [],
};
var getStateDiff = function (state, _a) {
    var _b = _a === void 0 ? {} : _a, type = _b.type, payload = _b.payload;
    switch (type) {
        case ListingActionTypes.SET_BASE_QUERIES:
            return {
                baseQueries: payload.baseQueries,
            };
        case ListingActionTypes.SET_ITEM_CACHE:
            return {
                itemCache: __assign(__assign({}, state.itemCache), payload.itemCache),
            };
        case ListingActionTypes.SET_VISIBLE_ITEM_IDS:
            return {
                visibleItemIds: payload.visibleItemIds,
            };
        case ListingActionTypes.SET_IS_LOADING:
            return {
                isLoading: payload.isLoading,
                loadingError: payload.isLoading ?
                    null :
                    state.loadingError,
            };
        case ListingActionTypes.SET_LOADING_ERROR:
            return {
                loadingError: payload.error,
            };
        default:
            return null;
    }
};
export default (function (state, action) {
    if (state === void 0) { state = initialState; }
    var stateDiff = getStateDiff(state, action);
    if (stateDiff) {
        return __assign(__assign({}, state), stateDiff);
    }
    return state;
});
//# sourceMappingURL=ListingReducer.js.map