UNPKG

@shopgate/pwa-tracking

Version:

Tracking library for the Shopgate Connect PWA.

13 lines 1.55 kB
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{createSelector}from'reselect';import{getSortOrder,getSearchPhrase}from'@shopgate/engage/core/selectors';import{generateResultHash}from'@shopgate/engage/core/helpers';import{getFulfillmentParams}from'@shopgate/pwa-common-commerce/product';/** * Selects the container for search results. * @param {Object} state The current state. * @returns {Object} The search results. */var resultsSelector=function resultsSelector(state){return state.product.resultsByHash;};/** * Selects the product count for a search result. * @param {Object} state The current state. * @returns {number} The total product count. */var resultCountSelector=createSelector(getSearchPhrase,getSortOrder,resultsSelector,getFulfillmentParams,function(searchPhrase,sort,results,fulfillmentParams){var hash=searchPhrase&&generateResultHash(_extends({sort:sort,searchPhrase:searchPhrase},fulfillmentParams));if(!hash||!results[hash]){return null;}return results[hash].totalResultCount;});/** * Selects the search information. * @param {Object} state The current state. * @returns {Object} The search information. */export default createSelector(getSearchPhrase,resultCountSelector,function(query,resultCount){if(!query&&!resultCount){return null;}return{query:query,resultCount:resultCount};});