@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
70 lines • 7.01 kB
JavaScript
import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{main$}from'@shopgate/pwa-common/streams/main';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import{userDidLogin$,userDidLogout$}from'@shopgate/pwa-common/streams/user';import{getCurrentPathname}from'@shopgate/pwa-common/selectors/router';import{WISH_LIST_PATH}from'@shopgate/engage/account/constants/routes';import{FAVORITES_PATH,ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,RECEIVE_FAVORITES,ERROR_FAVORITES,ERROR_FETCH_FAVORITES,REQUEST_ADD_FAVORITES,SUCCESS_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,SUCCESS_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,IDLE_SYNC_FAVORITES,REQUEST_FLUSH_FAVORITES_BUFFER,FAVORITES_LIMIT_ERROR,FETCH_FAVORITES_THROTTLE,FAVORITE_ACTION_BUFFER_TIME,FAVORITE_BUTTON_DEBOUNCE_TIME,SUCCESS_ADD_FAVORITES_LIST,REQUEST_UPDATE_FAVORITES,UPDATE_PRODUCT_IN_FAVORITES,FAVORITE_QUANTITY_DEBOUNCE_TIME}from"../constants";/**
* @link https://developer.shopgate.com/references/engage/streams/favorites
*/ /**
* Gets triggered when the favorites page is about to be entered.
* @type {Observable}
*/export var favoritesWillEnter$=routeWillEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===FAVORITES_PATH||action.route.pathname===WISH_LIST_PATH;});/**
* Gets triggered when ADD_PRODUCT_TO_FAVORITES action is dispatched
*/export var addProductToFavorites$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===ADD_PRODUCT_TO_FAVORITES;});/**
* Gets triggered when the debounce time of `addProductToFavorites` passes.
* @type {Observable}
*/export var addProductToFavoritesDebounced$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===ADD_PRODUCT_TO_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
* Gets triggered when the debounce time of `updateProductInFavorites` passes.
* @type {Observable}
*/export var updateProductInFavoritesDebounced$=main$.filter(function(_ref4){var action=_ref4.action;return action.type===UPDATE_PRODUCT_IN_FAVORITES;}).debounceTime(FAVORITE_QUANTITY_DEBOUNCE_TIME);/**
* Gets triggered when the debounce time of `removeProductFromFavorites` passes.
* @type {Observable}
*/export var removeProductFromFavoritesDebounced$=main$.filter(function(_ref5){var action=_ref5.action;return action.type===REMOVE_PRODUCT_FROM_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
* Gets triggered when any errors related to the favorite list occur.
* @type {Observable}
*/export var favoritesError$=main$.filter(function(_ref6){var action=_ref6.action;return[ERROR_FETCH_FAVORITES,ERROR_ADD_FAVORITES,ERROR_REMOVE_FAVORITES,ERROR_FAVORITES].includes(action.type);});/**
* Gets triggered when errors occur, that are only related to the frontend part of the
* favorite list.
* @type {Observable}
*/export var errorFavoritesLimit$=favoritesError$.filter(function(_ref7){var action=_ref7.action;return action.type===ERROR_FAVORITES&&action.error&&action.error.code===FAVORITES_LIMIT_ERROR;});/**
* Gets triggered when the app started or when the favorites page is about to be entered.
* @type {Observable}
*/export var shouldFetchFavorites$=favoritesWillEnter$.merge(appDidStart$);/**
* Gets triggered when the favorite list should be refreshed (without
* @type {Observable}
*/export var shouldFetchFreshFavorites$=userDidLogin$.merge(userDidLogout$);/**
* Gets triggered when the favorites updated in any way.
* @type {Observable}
*/export var favoritesDidUpdate$=main$.filter(function(_ref8){var action=_ref8.action;return[REQUEST_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,RECEIVE_FAVORITES,ERROR_FETCH_FAVORITES].includes(action.type);});/**
* Gets triggered when an "add to favorites" action is being placed into the favorite list buffer.
* @type {Observable}
*/export var favoritesWillAddItem$=main$.filter(function(_ref9){var action=_ref9.action;return action.type===REQUEST_ADD_FAVORITES;});/**
* Gets triggered when a single product has been successfully added to the favorite list.
* @type {Observable}
*/export var favoritesDidAddItem$=main$.filter(function(_ref10){var action=_ref10.action;return action.type===SUCCESS_ADD_FAVORITES;});/**
* Gets triggered when a "remove from favorites" action is being placed into the favorite
* list buffer.
* @type {Observable}
*/export var favoritesWillRemoveItem$=main$.filter(function(_ref11){var action=_ref11.action;return action.type===REQUEST_REMOVE_FAVORITES;});/**
* Gets triggered when a single product has been successfully removed from the favorite list.
* @type {Observable}
*/export var favoritesDidRemoveItem$=main$.filter(function(_ref12){var action=_ref12.action;return action.type===SUCCESS_REMOVE_FAVORITES;});/**
* Gets triggered when the favorite list has successfully been received from the backend.
* @type {Observable}
*/export var receiveFavorites$=main$.filter(function(_ref13){var action=_ref13.action;return action.type===RECEIVE_FAVORITES;});export var receiveFavoritesWhileVisible$=receiveFavorites$.filter(function(_ref14){var getState=_ref14.getState;var currentPath=getCurrentPathname(getState());return currentPath===FAVORITES_PATH||currentPath===WISH_LIST_PATH;});/**
* Gets triggered whenever all favorite changes have been successfully processed or once when
* any of the buffered change requests fails.
* @type {Observable}
*/export var favoritesSyncIdle$=main$.filter(function(_ref15){var action=_ref15.action;return action.type===IDLE_SYNC_FAVORITES;});/**
* Gets triggered after an favorites list has been added.
*/export var favoritesListAdded$=main$.filter(function(_ref16){var action=_ref16.action;return action.type===SUCCESS_ADD_FAVORITES_LIST;});/**
* Gets triggered when the favorites should be refreshed to maintain data consistency.
* @type {Observable}
*/export var refreshFavorites$=favoritesSyncIdle$.debounceTime(FETCH_FAVORITES_THROTTLE);/**
* Gets triggered when a product is requested to be added, removed or updated
* from the favorite list.
* @type {Observable}
*/export var didRequestChangeFavorites$=main$.filter(function(_ref17){var action=_ref17.action;return action.type===REQUEST_ADD_FAVORITES||action.type===REQUEST_REMOVE_FAVORITES||action.type===REQUEST_UPDATE_FAVORITES;});/**
* Gets triggered when the favorites action buffer should be flushed immediately.
* @type {Observable}
*/export var didRequestFlushFavoritesBuffer$=main$.filter(function(_ref18){var action=_ref18.action;return action.type===REQUEST_FLUSH_FAVORITES_BUFFER;});/**
* Gets triggered when the favorites buffer is supposed to be flushed after some delay time or
* when the `requestFlushFavoritesBuffer` action was triggered.
* @type {Observable}
*/export var didReceiveFlushFavoritesBuffer$=didRequestChangeFavorites$.buffer(didRequestChangeFavorites$.debounceTime(FAVORITE_ACTION_BUFFER_TIME)// Compress delayed actions into a single one
.merge(didRequestFlushFavoritesBuffer$));