UNPKG

@shopgate/pwa-tracking

Version:

Tracking library for the Shopgate Connect PWA.

12 lines 1.42 kB
import{createSelector}from'reselect';import{makeGetRouteParam,makeGetRoutePattern}from'@shopgate/engage/core/selectors';import{hex2bin}from'@shopgate/engage/core/helpers';import{ITEM_PATTERN}from'@shopgate/engage/product/constants';import{getBaseProduct,getProduct}from'@shopgate/pwa-common-commerce/product/selectors/product';import{formatProductData}from"../helpers";/** * Gets the current base product in a formatted way. * @param {Object} state The current state. * @returns {Object} The formatted selected variant. */export var getBaseProductFormatted=createSelector(getBaseProduct,formatProductData);/** * Gets the current product in a formatted way. * @param {Object} state The current state. * @returns {Object} The formatted selected variant. */export var getProductFormatted=createSelector(getProduct,formatProductData);/** * Creates a selector that retrieves a formatted product for the current route. * @returns {Function} */export var makeGetRouteProduct=function makeGetRouteProduct(){var getRoutePattern=makeGetRoutePattern();var getProductIdRouteParam=makeGetRouteParam('productId');return createSelector(function(state){return state;},getRoutePattern,getProductIdRouteParam,function(state,pattern,productId){var decodedProductId=productId?hex2bin(productId):null;if(pattern===ITEM_PATTERN&&decodedProductId){return getProductFormatted(state,{productId:decodedProductId});}return null;});};