UNPKG

@shopgate/engage

Version:
17 lines 1.56 kB
import{createSelector}from'reselect';import{getCategoryChildren,getRootCategories,getRootCategoriesState,getChildCategoriesForCategory}from'@shopgate/pwa-common-commerce/category/selectors';/** * Creates a getCategoriesById selector * @returns {Function} */export var makeGetSubcategoriesByCategoryId=function makeGetSubcategoriesByCategoryId(){return(/** * Retrieves categories from the state. * If no category id is passed, root-categories will be returned. * @param {Object} state The application state. * @param {Object} props The component props. * @returns {Object[]} The categories collection. */createSelector(getCategoryChildren,getRootCategories,function(state,props){return props.categoryId;},function(childCategories,rootCategories,categoryId){// Check if we have to handle the root-category if(!categoryId&&rootCategories){return rootCategories;}return childCategories;}));};/** * Creates a getAreRootCategoriesFetching selector * @returns {Function} */export var makeGetAreRootCategoriesFetching=function makeGetAreRootCategoriesFetching(){return createSelector(getRootCategoriesState,function(rootCategories){return(rootCategories===null||rootCategories===void 0?void 0:rootCategories.isFetching)||false;});};/** * Creates a getIsCategoryFetching selector * @returns {Function} */export var makeGetAreChildCategoriesFetching=function makeGetAreChildCategoriesFetching(){return createSelector(getChildCategoriesForCategory,function(category){return(category===null||category===void 0?void 0:category.isFetching)||false;});};