UNPKG

@shopgate/engage

Version:
1 lines 7.76 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{main$}from'@shopgate/pwa-common/streams';import{Observable}from'rxjs/Observable';import{cartReceived$}from'@shopgate/pwa-common-commerce/cart/streams';import{makeGetRoutePattern,getCurrentState,getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{ITEM_PATTERN}from'@shopgate/pwa-common-commerce/product/constants';import{getProductDataById}from'@shopgate/pwa-common-commerce/product/selectors/product';import{SEARCH_PATTERN}from'@shopgate/pwa-common-commerce/search/constants';import{CATEGORY_PATTERN}from'@shopgate/pwa-common-commerce/category/constants';import{FAVORITES_PATH}from'@shopgate/pwa-common-commerce/favorites/constants';import{SUBMIT_RESERVATION_SUCCESS,RECEIVE_PRODUCT_LOCATIONS,RECEIVE_LOCATIONS,SET_USER_SEARCH_COUNTRY_CODE,SET_USER_SEARCH_POSTAL_CODE,SET_USER_SEARCH_GEOLOCATION,SET_STORE_FINDER_SEARCH_RADIUS,SELECT_GLOBAL_LOCATION,STORE_FINDER_PATTERN,PROVIDE_PRODUCT_ALTERNATIVE_LOCATION,SELECT_LOCATION,STORE_DETAILS_PATTERN}from"./constants";import{RECEIVE_ORDER_DETAILS}from"../orders/constants";import{WISH_LIST_PATH}from"../account/constants";export var submitReservationSuccess$=main$.filter(function(_ref){var action=_ref.action;return action.type===SUBMIT_RESERVATION_SUCCESS;});export var receiveProductLocations$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===RECEIVE_PRODUCT_LOCATIONS;});export var receiveOrderDetails$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===RECEIVE_ORDER_DETAILS;});export var cartReceivedWithROPE$=cartReceived$.filter(function(_ref4){var _ref4$action$cart=_ref4.action.cart,_ref4$action$cart2=_ref4$action$cart===void 0?{}:_ref4$action$cart,_ref4$action$cart2$ca=_ref4$action$cart2.cartItems,cartItems=_ref4$action$cart2$ca===void 0?[]:_ref4$action$cart2$ca;return cartItems.some(function(item){var _item$fulfillment,_item$fulfillment$loc;return item===null||item===void 0?void 0:(_item$fulfillment=item.fulfillment)===null||_item$fulfillment===void 0?void 0:(_item$fulfillment$loc=_item$fulfillment.location)===null||_item$fulfillment$loc===void 0?void 0:_item$fulfillment$loc.code;});});export var userSearchChanged$=main$.filter(function(_ref5){var action=_ref5.action;return action.type===SET_USER_SEARCH_COUNTRY_CODE||action.type===SET_USER_SEARCH_POSTAL_CODE||action.type===SET_USER_SEARCH_GEOLOCATION||action.type===SET_STORE_FINDER_SEARCH_RADIUS;});export var fulfillmentLocationsReceivedFromProduct$=receiveProductLocations$.switchMap(function(data){var locations=data.action.locations;var locationCodes=locations.map(function(_ref6){var code=_ref6.code;return code;});return Observable.of(_extends({},data,{locationCodes:locationCodes}));});export var fulfillmentLocationsReceivedFromCart$=cartReceivedWithROPE$.switchMap(function(data){var _data$action$cart=data.action.cart,_data$action$cart2=_data$action$cart===void 0?{}:_data$action$cart,_data$action$cart2$ca=_data$action$cart2.cartItems,cartItems=_data$action$cart2$ca===void 0?[]:_data$action$cart2$ca;var locationCodes=cartItems.map(function(item){var _item$fulfillment2,_item$fulfillment2$lo;return item===null||item===void 0?void 0:(_item$fulfillment2=item.fulfillment)===null||_item$fulfillment2===void 0?void 0:(_item$fulfillment2$lo=_item$fulfillment2.location)===null||_item$fulfillment2$lo===void 0?void 0:_item$fulfillment2$lo.code;}).filter(Boolean);locationCodes=Array.from(new Set(locationCodes));return Observable.of(_extends({},data,{locationCodes:locationCodes}));});export var fulfillmentLocationsReceivedFromOrder$=receiveOrderDetails$.filter(function(_ref7){var _ref7$action$order=_ref7.action.order,_ref7$action$order2=_ref7$action$order===void 0?{}:_ref7$action$order,_ref7$action$order2$l=_ref7$action$order2.lineItems,lineItems=_ref7$action$order2$l===void 0?[]:_ref7$action$order2$l;return lineItems.some(function(item){return item.fulfillmentLocationCode;});}).switchMap(function(data){var _data$action$order=data.action.order,_data$action$order2=_data$action$order===void 0?{}:_data$action$order,_data$action$order2$l=_data$action$order2.lineItems,lineItems=_data$action$order2$l===void 0?[]:_data$action$order2$l;var locationCodes=lineItems.map(function(item){return item===null||item===void 0?void 0:item.fulfillmentLocationCode;}).filter(Boolean);locationCodes=Array.from(new Set(locationCodes));return Observable.of(_extends({},data,{locationCodes:locationCodes}));});export var fulfillmentLocationsReceived$=fulfillmentLocationsReceivedFromCart$.merge(fulfillmentLocationsReceivedFromOrder$).merge(fulfillmentLocationsReceivedFromProduct$);export var preferredLocationDidUpdateGlobal$=main$.filter(function(_ref8){var action=_ref8.action;return action.type===SELECT_GLOBAL_LOCATION;});export var preferredLocationDidUpdateGlobalOnWishlist$=preferredLocationDidUpdateGlobal$.filter(function(_ref9){var getState=_ref9.getState;var _getCurrentRoute=getCurrentRoute(getState()),pattern=_getCurrentRoute.pattern;return pattern===FAVORITES_PATH||pattern===WISH_LIST_PATH;});export var preferredLocationDidUpdateGlobalOnSearch$=preferredLocationDidUpdateGlobal$.filter(function(_ref10){var getState=_ref10.getState;var _getCurrentRoute2=getCurrentRoute(getState()),pattern=_getCurrentRoute2.pattern;return pattern===SEARCH_PATTERN;});export var preferredLocationDidUpdateGlobalNotOnSearch$=preferredLocationDidUpdateGlobal$.filter(function(_ref11){var getState=_ref11.getState;var _getCurrentRoute3=getCurrentRoute(getState()),pattern=_getCurrentRoute3.pattern;return pattern!==SEARCH_PATTERN;});export var preferredLocationDidUpdateGlobalOnCategory$=preferredLocationDidUpdateGlobal$.filter(function(_ref12){var getState=_ref12.getState;var _getCurrentRoute4=getCurrentRoute(getState()),pattern=_getCurrentRoute4.pattern;return pattern===CATEGORY_PATTERN;});export var preferredLocationDidUpdateGlobalNotOnCategory$=preferredLocationDidUpdateGlobal$.filter(function(_ref13){var getState=_ref13.getState;var _getCurrentRoute5=getCurrentRoute(getState()),pattern=_getCurrentRoute5.pattern;return pattern!==CATEGORY_PATTERN;});export var preferredLocationDidUpdate$=main$.filter(function(_ref14){var action=_ref14.action;return action.type===SELECT_LOCATION;});export var storeFinderWillEnter$=routeWillEnter$.filter(function(_ref15){var action=_ref15.action;return action.route.pattern===STORE_FINDER_PATTERN;});export var receiveLocations$=main$.filter(function(_ref16){var action=_ref16.action;return action.type===RECEIVE_LOCATIONS;});export var provideAlternativeLocation$=main$.filter(function(_ref17){var action=_ref17.action;return action.type===PROVIDE_PRODUCT_ALTERNATIVE_LOCATION;});export var preferredLocationDidUpdateOnPDP$=preferredLocationDidUpdateGlobal$.filter(function(_ref18){var getState=_ref18.getState;var getRoutePattern=makeGetRoutePattern();var routePattern=getRoutePattern(getState());return routePattern===ITEM_PATTERN;}).switchMap(function(_ref19){var dispatch=_ref19.dispatch,getState=_ref19.getState,action=_ref19.action;var state=getState();var _getCurrentState=getCurrentState(state),productId=_getCurrentState.productId;var productData=getProductDataById(state,{productId:productId});return Observable.of({action:_extends({},action,{productData:productData}),dispatch:dispatch,getState:getState});});export var storeDetailPageWillEnter$=routeWillEnter$.filter(function(_ref20){var action=_ref20.action;return action.route.pattern===STORE_DETAILS_PATTERN;});