How to use the @shopgate/pwa-common/streams/history.routeDidEnter function in @shopgate/pwa-common

To help you get started, we’ve selected a few @shopgate/pwa-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / commerce / category / streams / index.js View on Github external
import { FILTER_PATH } from '../../filter/constants';

/**
 * Gets triggered when leaving a category route.
 * When opening the filter page the categoryId should be preserved
 * so that the filters know what category needs to be filtered.
 */
export const categoryRouteDidLeave$ = routeDidLeave(CATEGORY_PATH).filter(({ pathname }) => (
  // A transition to filters should not count as 'leaving'.
  !pathname.startsWith(FILTER_PATH)
));

/**
 * Gets triggered when entering a category route.
 */
export const categoryRouteDidEnter$ = routeDidEnter(CATEGORY_PATH);

/**
 * Gets triggered when the root categories received.
 */
export const receivedRootCategories$ = main$.filter(({ action }) => (
  action.type === RECEIVE_ROOT_CATEGORIES
));
github shopgate / pwa / pages / Browse / subscriptions.js View on Github external
export default function browse(subscribe) {
  // Derived streams.
  const browseRouteDidEnter$ = routeDidEnter(BROWSE_PATH);

  /**
   * Gets triggered on entering the browse route. Resets the search phrase.
   */
  subscribe(browseRouteDidEnter$, ({ dispatch }) => dispatch(setSearchPhrase('')));
}
github shopgate / pwa / components / Navigator / subscriptions.js View on Github external
export default function navigator(subscribe) {
  // Derived streams.
  const searchRouteDidEnter$ = routeDidEnter(SEARCH_PATH);
  const cartFilterRoutesDidEnter$ = routeDidEnter(CART_PATH).merge(routeDidEnter(FILTER_PATH));
  const cartFilterRoutesDidLeave$ = routeDidLeave(CART_PATH).merge(routeDidLeave(FILTER_PATH));

  /**
   * Gets triggered on all route changes.
   */
  subscribe(routeDidChange$, ({ dispatch, pathname, prevPathname }) => {
    if (pathname !== prevPathname) {
      dispatch(toggleNavSearchField(false));
    }
  });

  /**
   * Gets triggered on entering the search route.
   */
  subscribe(searchRouteDidEnter$, ({ dispatch, getState }) => {
github shopgate / pwa / pages / Reviews / subscriptions.js View on Github external
export default function reviews(subscribe) {
  const reviewsRouteDidEnter$ = routeDidEnter(ITEM_PATH).filter(({ pathname }) => pathname.endsWith('reviews') || pathname.endsWith('reviews/'));

  /**
   * Gets triggered on entering the reviews route.
   */
  subscribe(reviewsRouteDidEnter$, ({ dispatch, getState }) => {
    const currentCount = getCurrentReviewCount(getState());
    if (currentCount >= REVIEW_ITEMS_PER_PAGE) {
      // No need to fetch.
      return;
    }
    dispatch(fetchReviews(getCurrentBaseProductId(getState()), REVIEW_ITEMS_PER_PAGE));
  });
}
github shopgate / pwa / pages / User / AddressBook / subscriptions.js View on Github external
export default (subscribe) => {
  const userAddressesRouteDidEnter$ = routeDidEnter(userAddressesRoute);
  const userAddressesRouteDidLeave$ = routeDidLeave(userAddressesRoute);

  // Hide top nav elements
  subscribe(userAddressesRouteDidEnter$, ({ dispatch }) => {
    dispatch(disableNavigatorSearch());
    dispatch(toggleCartIcon(false));
  });

  // UnHide top nav elements
  subscribe(userAddressesRouteDidLeave$, ({ dispatch }) => {
    dispatch(enableNavigatorSearch());
    dispatch(toggleCartIcon(true));
  });
};
github shopgate / pwa / components / Navigator / subscriptions.js View on Github external
export default function navigator(subscribe) {
  // Derived streams.
  const searchRouteDidEnter$ = routeDidEnter(SEARCH_PATH);
  const cartFilterRoutesDidEnter$ = routeDidEnter(CART_PATH).merge(routeDidEnter(FILTER_PATH));
  const cartFilterRoutesDidLeave$ = routeDidLeave(CART_PATH).merge(routeDidLeave(FILTER_PATH));

  /**
   * Gets triggered on all route changes.
   */
  subscribe(routeDidChange$, ({ dispatch, pathname, prevPathname }) => {
    if (pathname !== prevPathname) {
      dispatch(toggleNavSearchField(false));
    }
  });

  /**
   * Gets triggered on entering the search route.
   */
  subscribe(searchRouteDidEnter$, ({ dispatch, getState }) => {
    const state = getState();
github shopgate / pwa / pages / Search / subscriptions.js View on Github external
export default function search(subscribe) {
  const searchRouteDidEnter$ = routeDidEnter(SEARCH_PATH);
  const searchRouteDidLeave$ = routeDidLeave(SEARCH_PATH);

  /**
   * Gets triggered on entering the search route.
   */
  subscribe(searchRouteDidEnter$, ({ dispatch }) => {
    dispatch(toggleProgressBar(false));
  });

  /**
   * Gets triggered on leaving the search route.
   */
  subscribe(searchRouteDidLeave$, ({ dispatch }) => {
    dispatch(toggleProgressBar(true));
  });
}
github shopgate / pwa / pages / Filter / subscriptions.js View on Github external
export default function filter(subscribe) {
  const filterRouteDidEnter$ = routeDidEnter(FILTER_PATH);
  const filterRouteDidLeave$ = routeDidLeave(FILTER_PATH);

  /**
   * Gets triggered on leaving the filter route.
   */
  subscribe(filterRouteDidLeave$, ({ dispatch, pathname }) => {
    if (!pathname.startsWith(FILTER_PATH)) {
      dispatch(setFilterClosed());
    }
  });

  /**
   * Gets triggered on entering the filter route.
   */
  subscribe(filterRouteDidEnter$, ({ dispatch, prevPathname }) => {
    if (!prevPathname.startsWith(FILTER_PATH)) {
github shopgate / pwa / pages / Product / subscriptions.js View on Github external
export default function product(subscribe) {
  const writeReviewRouteDidEnter$ = routeDidEnter(ITEM_PATH).filter((
    ({ pathname }) => pathname.endsWith('write_review') || pathname.endsWith('write_review/')
  ));

  const reviewsRouteDidEnter$ = routeDidEnter(ITEM_PATH).filter((
    ({ pathname }) => pathname.endsWith('reviews') || pathname.endsWith('reviews/')
  ));

  const productRouteDidEnter$ = routeDidEnter(ITEM_PATH).filter((
    ({ pathname }) => !(pathname.endsWith('reviews') || pathname.endsWith('reviews/')
      || pathname.endsWith('write_review') || pathname.endsWith('write_review/'))
  ));

  /**
   * Gets triggered on entering any product route.
   */
  subscribe(routeDidEnter(ITEM_PATH), ({ dispatch, getState }) => {
    const productId = getCurrentBaseProductId(getState());
    dispatch(getProduct(productId));
  });
github shopgate / pwa / pages / Category / subscriptions.js View on Github external
export default function category(subscribe) {
  const categoryRouteDidEnter$ = routeDidEnter(CATEGORY_PATH);

  /**
   * Gets triggered on entering the filter route.
   */
  subscribe(categoryRouteDidEnter$, ({ dispatch, getState }) => {
    const state = getState();
    dispatch(getCategory(getCurrentCategoryId(state)));
  });
}