UNPKG

@shopgate/pwa-common-commerce

Version:

Commerce library for the Shopgate Connect PWA.

10 lines 4.07 kB
import{main$,routeWillEnter$,routeDidEnter$,routeDidLeave$,routeWillLeave$}from'@shopgate/pwa-common/streams';import{routeDidUpdate$}from'@shopgate/pwa-common/streams/router';import{HISTORY_POP_ACTION}from'@shopgate/pwa-common/constants/ActionTypes';import{filtersDidUpdate$}from'@shopgate/pwa-common-commerce/filter/streams';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{hex2bin}from'@shopgate/pwa-common/helpers/data';import{filterWillLeave$}from"../../filter/streams";import{CATEGORY_PATTERN,CATEGORY_ALL_PATTERN,RECEIVE_ROOT_CATEGORIES,ERROR_CATEGORY,RECEIVE_CATEGORY,CATEGORY_PATH}from"../constants";export var categoryWillEnter$=routeWillEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===CATEGORY_PATTERN;});export var categoryDidEnter$=routeDidEnter$.filter(function(_ref2){var action=_ref2.action;return action.route.pattern===CATEGORY_PATTERN;});export var categoryDidLeave$=routeDidLeave$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===CATEGORY_PATTERN;});export var categoryAllWillEnter$=routeWillEnter$.filter(function(_ref4){var action=_ref4.action;return action.route.pattern===CATEGORY_ALL_PATTERN;});export var categoryAllDidEnter$=routeDidEnter$.filter(function(_ref5){var action=_ref5.action;return action.route.pattern===CATEGORY_ALL_PATTERN;});export var categoryAllDidLeave$=routeDidLeave$.filter(function(_ref6){var action=_ref6.action;return action.route.pattern===CATEGORY_ALL_PATTERN;});/** * Gets triggered when the root categories received. */export var receivedRootCategories$=main$.filter(function(_ref7){var action=_ref7.action;return action.type===RECEIVE_ROOT_CATEGORIES;});/** * Gets trigger when category error is dispatched. */export var categoryError$=main$.filter(function(_ref8){var action=_ref8.action;return action.type===ERROR_CATEGORY;});export var categoryDidBackEnter$=categoryDidEnter$.filter(function(_ref9){var action=_ref9.action;return action.historyAction===HISTORY_POP_ACTION;});export var categoryWillLeave$=routeWillLeave$.filter(function(_ref10){var action=_ref10.action;return action.route.pattern==="".concat(CATEGORY_PATH,"/:categoryId");});/** * Filters stream state by type. * @param {Object} data The stream data. * @param {string} type The action type to filter. * @returns {boolean} */var filterDataByType=function filterDataByType(data,type){var action=data.action,getState=data.getState;if(action.type!==type){return false;}if(typeof action.categoryId==='undefined'){return false;}var route=getCurrentRoute(getState());if(!route.params.categoryId){return false;}return action.categoryId===hex2bin(route.params.categoryId);};export var receivedVisibleCategory$=main$.filter(function(data){return filterDataByType(data,RECEIVE_CATEGORY);});export var errorVisibleCategory$=main$.filter(function(data){return filterDataByType(data,ERROR_CATEGORY);});export var categoryFiltersDidUpdate$=filtersDidUpdate$.filter(function(_ref11){var getState=_ref11.getState;var _getCurrentRoute=getCurrentRoute(getState()),pattern=_getCurrentRoute.pattern;return pattern===CATEGORY_PATTERN;});export var categoryDidUpdate$=routeDidUpdate$.filter(function(_ref12){var _action$route;var action=_ref12.action;return(action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.pattern)===CATEGORY_PATTERN;});export var categoryAllDidUpdate$=routeDidUpdate$.filter(function(_ref13){var _action$route2;var action=_ref13.action;return(action===null||action===void 0?void 0:(_action$route2=action.route)===null||_action$route2===void 0?void 0:_action$route2.pattern)===CATEGORY_ALL_PATTERN;});export var categoryFiltersDidUpdateFromFilterPage$=categoryDidUpdate$.switchMap(function(){return filterWillLeave$.first();}).switchMap(function(){return categoryWillEnter$.first();});export var categoryAllFiltersDidUpdateFromFilterPage$=categoryAllDidUpdate$.switchMap(function(){return filterWillLeave$.first();}).switchMap(function(){return categoryAllWillEnter$.first();});