@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
7 lines • 3.06 kB
JavaScript
import{ACTION_REPLACE}from'@virtuous/conductor';import{main$}from'@shopgate/pwa-common/streams/main';import{routeWillEnter$,routeDidEnter$,routeWillLeave$,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{SEARCH_PATH}from'@shopgate/pwa-common-commerce/search/constants';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{preferredLocationDidUpdate$,preferredLocationDidUpdateGlobalNotOnSearch$,preferredLocationDidUpdateGlobalOnSearch$}from'@shopgate/engage/locations/locations.streams';import{CATEGORY_ALL_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{filterWillLeave$}from"../../filter/streams";import{REQUEST_SEARCH_RESULTS,RECEIVE_SEARCH_RESULTS,ERROR_SEARCH_RESULTS,SEARCH_PATTERN}from"../constants";/**
* Gets triggered when search results are requested.
* @type {Observable}
*/export var searchRequesting$=main$.filter(function(_ref){var action=_ref.action;return action.type===REQUEST_SEARCH_RESULTS;});/**
* Gets triggered when search results are received.
* @type {Observable}
*/export var searchReceived$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===RECEIVE_SEARCH_RESULTS||action.type===ERROR_SEARCH_RESULTS;});export var searchWillEnter$=routeWillEnter$.filter(function(_ref3){var action=_ref3.action;return action.route.pattern===SEARCH_PATTERN;});export var searchDidEnter$=routeDidEnter$.filter(function(_ref4){var action=_ref4.action;return action.route.pattern===SEARCH_PATTERN;});export var searchWillLeave$=routeWillLeave$.filter(function(_ref5){var action=_ref5.action;return action.route.pattern===SEARCH_PATTERN;});export var searchWillUpdate$=routeWillEnter$.filter(function(_ref6){var action=_ref6.action;return action.route.pattern===SEARCH_PATTERN&&action.historyAction===ACTION_REPLACE;});export var searchDidBackEntered$=searchDidEnter$.filter(function(_ref7){var action=_ref7.action;return action.historyAction===HISTORY_POP_ACTION;});export var searchFiltersDidUpdate$=filtersDidUpdate$.filter(function(_ref8){var getState=_ref8.getState;var _getCurrentRoute=getCurrentRoute(getState()),pattern=_getCurrentRoute.pattern;return pattern===SEARCH_PATH||pattern===CATEGORY_ALL_PATTERN;});export var searchProductsNeedUpdate$=preferredLocationDidUpdate$.merge(preferredLocationDidUpdateGlobalNotOnSearch$).switchMap(function(){return searchDidBackEntered$.first();}).merge(searchFiltersDidUpdate$).merge(preferredLocationDidUpdateGlobalOnSearch$);export var searchDidUpdate$=routeDidUpdate$.filter(function(_ref9){var _action$route;var action=_ref9.action;return(action===null||action===void 0?void 0:(_action$route=action.route)===null||_action$route===void 0?void 0:_action$route.pattern)===SEARCH_PATTERN;});export var searchFiltersDidUpdateFromFilterPage$=searchDidUpdate$.switchMap(function(){return filterWillLeave$.first();}).switchMap(function(){return searchWillEnter$.first();});