@shopgate/pwa-tracking
Version:
Tracking library for the Shopgate Connect PWA.
4 lines • 1.13 kB
JavaScript
import{createSelector}from'reselect';import{hex2bin}from'@shopgate/engage/core/helpers';import{makeGetRouteParam,makeGetRoutePattern}from'@shopgate/engage/core/selectors';import{CATEGORY_PATTERN,ROOT_CATEGORY_PATTERN}from'@shopgate/engage/category/constants';import{getRootCategories,getCategory}from'@shopgate/engage/category/selectors';import{createCategoryData,createRootCategoryData}from"../helpers";/**
* Creates a selector that retrieves a formatted category for the current route.
* @returns {Function}
*/export var makeGetRouteCategory=function makeGetRouteCategory(){var getRoutePattern=makeGetRoutePattern();var getCategoryIdRouteParam=makeGetRouteParam('categoryId');return createSelector(function(state){return state;},getRoutePattern,getCategoryIdRouteParam,getRootCategories,function(state,pattern,categoryId,rootCategories){var decodedCategoryId=categoryId?hex2bin(categoryId):null;if(pattern===ROOT_CATEGORY_PATTERN){return createRootCategoryData(rootCategories);}if(pattern===CATEGORY_PATTERN&&decodedCategoryId){return createCategoryData(getCategory(state,{categoryId:decodedCategoryId}));}return null;});};