@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
5 lines • 1.05 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{PRODUCT_LIFETIME}from"../../constants";/**
* Builds state entries from a collection of products (Array).
* @param {Array} products A products collection.
* @return {Object} The product entries for the state.
*/var handleProductCollection=function handleProductCollection(products){if(!Array.isArray(products)){return{};}return products.reduce(function(currentProducts,productData){return _extends({},currentProducts,_defineProperty({},productData.id,{productData:productData,isFetching:false,expires:Date.now()+PRODUCT_LIFETIME}));},{});};export default handleProductCollection;