UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

8 lines 1.56 kB
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_URL,RECEIVE_URL,ERROR_URL}from"../../constants/ActionTypes";var URL_LIFETIME=300000;// 5 minutes in milliseconds var defaultState={};/** * Stores the requested urls * This part of the store is stored in the localStorage! * @param {Object} [state] The current state. * @param {Object} action The action object. * @return {Object} The new state. */export default function urlReducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case REQUEST_URL:return _extends({},state,_defineProperty({},action.urlType,_extends({},state[action.urlType],{url:null,isFetching:true,expires:0})));case RECEIVE_URL:return _extends({},state,_defineProperty({},action.urlType,_extends({},state[action.urlType],{url:action.url,isFetching:false,expires:action.expires?Date.parse(action.expires):Date.now()+URL_LIFETIME})));case ERROR_URL:return _extends({},state,_defineProperty({},action.urlType,_extends({},state[action.urlType],{url:null,isFetching:false,expires:0})));default:return state;}}