@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
5 lines • 1.28 kB
JavaScript
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN}from"../constants/Pipelines";import requestCategoryChildren from"../action-creators/requestCategoryChildren";import receiveCategoryChildren from"../action-creators/receiveCategoryChildren";import errorCategoryChildren from"../action-creators/errorCategoryChildren";/**
* Retrieves category children for a certain category by ID.
* @param {string} categoryId The ID of the category to request children for.
* @return {Function} The dispatched action.
*/function fetchCategoryChildren(categoryId){return function(dispatch,getState){var category=getState().category.childrenByCategoryId[categoryId];if(!shouldFetchData(category,'children')){return Promise.resolve(null);}dispatch(requestCategoryChildren(categoryId));var request=new PipelineRequest(SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN).setInput({categoryId:categoryId}).dispatch();request.then(function(result){dispatch(receiveCategoryChildren(categoryId,result.categories));})["catch"](function(){dispatch(errorCategoryChildren(categoryId));});return request;};}/** @mixes {MutableFunction} */export default mutable(fetchCategoryChildren);