@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
6 lines • 1.14 kB
JavaScript
function _objectDestructuringEmpty(obj){if(obj==null)throw new TypeError("Cannot destructure undefined");}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{CATEGORY_LIFETIME}from"../../constants";/**
* Builds state entries from a collection of categories.
* @param {Array} collection A category collection.
* @return {Object} The category entries for the state.
*/var handleCategoryCollection=function handleCategoryCollection(collection){var categoryObjects={};// Is used to set them all to the same date because they arrived at the same time.
var expires=Date.now()+CATEGORY_LIFETIME;if(!collection){return categoryObjects;}collection.forEach(function(category){var categoryData=_extends({},(_objectDestructuringEmpty(category),category));categoryObjects[category.id]=_extends({},categoryData,{isFetching:false,expires:expires});});return categoryObjects;};export default handleCategoryCollection;