@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
6 lines • 1.51 kB
JavaScript
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{REQUEST_FILTERS,RECEIVE_FILTERS,ERROR_FILTERS}from'@shopgate/pwa-common-commerce/filter/constants';// TODO: Remove dependency to product
import{PRODUCT_LIFETIME}from'@shopgate/pwa-common-commerce/product/constants';import enrichFilters from"./helpers/enrichFilters";/**
* @param {Object} [state={}] The current state.
* @param {Object} action The current redux action.
* @return {Object} The new state.
*/export default function resultsByHash(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_FILTERS:{return _extends({},state,_defineProperty({},action.hash,{filters:null,isFetching:true,expires:0}));}case RECEIVE_FILTERS:{return _extends({},state,_defineProperty({},action.hash,{filters:enrichFilters(action.filters),isFetching:false,expires:Date.now()+PRODUCT_LIFETIME}));}case ERROR_FILTERS:return _extends({},state,_defineProperty({},action.hash,_extends({},state[action.hash],{isFetching:false})));default:return state;}}