UNPKG

@shopgate/pwa-common-commerce

Version:

Commerce library for the Shopgate Connect PWA.

4 lines 2.48 kB
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{router}from'@shopgate/pwa-common/helpers/router';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import{buildFilterParamsForFetchFiltersRequest}from'@shopgate/engage/filter/helpers';import{CATEGORY_ALL_FILTER_PATTERN}from"../../category/constants";import fetchCategory from"../../category/actions/fetchCategory";import{getShowAllProductsFilters}from"../../category/helpers";import fetchFilters from"../actions/fetchFilters";import{filterDidEnter$}from"../streams";/** * Filters subscriptions. * @param {Function} subscribe The subscribe function. */export default function filters(subscribe){subscribe(filterDidEnter$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var _action$route,_action$route2;var dispatch,action,_ref3,routeFilters,category;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,action=_ref.action;_ref3=(action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.state)||{},routeFilters=_ref3.filters;if(!((action===null||action===void 0?void 0:(_action$route2=action.route)===null||_action$route2===void 0?void 0:_action$route2.pattern)===CATEGORY_ALL_FILTER_PATTERN)){_context.next=9;break;}if(routeFilters){_context.next=9;break;}_context.next=6;return dispatch(fetchCategory(hex2bin(action.route.params.categoryId)));case 6:category=_context.sent;routeFilters=getShowAllProductsFilters(category);router.update(action.route.id,{filters:routeFilters,categoryName:category.name});case 9:dispatch(fetchFilters({filters:buildFilterParamsForFetchFiltersRequest(routeFilters)}));case 10:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());}