How to use the @shopgate/pwa-common/streams/main.main$.filter 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 / themes / theme-ios11 / pages / Product / components / AddToCartBar / subscriptions.js View on Github external
import { ERROR_ADD_PRODUCTS_TO_CART } from '@shopgate/pwa-common-commerce/cart/constants';
import { productsUpdated$, productsAdded$ } from '@shopgate/pwa-common-commerce/cart/streams';
import { variantDidChange$ } from '@shopgate/pwa-common-commerce/product/streams';
import { routeDidEnter$, routeDidLeave$ } from '@shopgate/pwa-common/streams/router';
import * as constants from './constants';
import * as actions from './action-creators';

const itemRouteDidEnter$ = routeDidEnter$
  .filter(({ action }) => action.route.pattern === ITEM_PATTERN);
const itemRouteDidLeave$ = routeDidLeave$
  .filter(({ action }) => action.route.pattern === ITEM_PATTERN);
const productNotAdded$ = productsUpdated$
  .filter(({ action }) => action.type === ERROR_ADD_PRODUCTS_TO_CART);
const incrementActionCount$ = main$
  .filter(({ action }) => action.type === constants.INCREMENT_ACTION_COUNT);
const decrementActionCount$ = main$
  .filter(({ action }) => action.type === constants.DECREMENT_ACTION_COUNT);
const resetActionCount$ = main$
  .filter(({ action }) => action.type === constants.RESET_ACTION_COUNT);
const showAddToCartBar$ = main$
  .filter(({ action }) => action.type === constants.SHOW_ADD_TO_CART_BAR);
const hideAddToCartBar$ = main$
  .filter(({ action }) => action.type === constants.HIDE_ADD_TO_CART_BAR);

/**
 * AddToCartBar subscriptions.
 * @param {Function} subscribe The subscribe function.
 */
export default function addToCartBar(subscribe) {
  subscribe(incrementActionCount$, ({ events, action }) => {
    events.emit(constants.INCREMENT_ACTION_COUNT, action.count);
  });
github shopgate / pwa / libraries / commerce / reviews / streams / index.js View on Github external
action.type === REQUEST_SUBMIT_REVIEW
));

/**
 * Gets triggered when the user tried to submit a review.
 * @type {Observable}
 */
export const responseReviewSubmit$ = main$.filter(({ action }) => (
  [RECEIVE_SUBMIT_REVIEW, ERROR_SUBMIT_REVIEW, RESET_SUBMIT_REVIEW].includes(action.type)
));

/**
 * Gets triggered when the user submit was successful.
 * @type {Observable}
 */
export const successReviewSubmit$ = main$.filter(({ action }) => (
  action.type === RECEIVE_SUBMIT_REVIEW
));

/**
 * Gets triggered when the user submit was not successful.
 * @type {Observable}
 */
export const errorReviewSubmit$ = main$.filter(({ action }) => (
  [ERROR_SUBMIT_REVIEW, RESET_SUBMIT_REVIEW].includes(action.type)
));

export const shouldFetchReviews$ = main$
  .filter(({ action }) => (
    (action.type === RECEIVE_PRODUCT || action.type === RECEIVE_PRODUCT_CACHED)
    && getCurrentRoute().pattern.startsWith(ITEM_PATH)
  ))
github shopgate / pwa / frontend / DeleteAccount / subscribers.js View on Github external
export default (subscribe) => {
  const deleteAccountRequested$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_REQUESTED');
  const deleteAccountSuccess$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_SUCCESS');
  const deleteAccountFailed$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_FAILED');

  subscribe(deleteAccountRequested$, async ({ dispatch }) => {
    const confirmed = await dispatch(showModal({
      message: 'user.delete_account_confirm',
      title: null,
    }));
    if (confirmed) {
      deleteAccountAction()(dispatch);
    }
  });

  subscribe(deleteAccountSuccess$, ({ dispatch }) => {
    dispatch({
      type: 'TOGGLE_NAV_DRAWER',
github shopgate / pwa / frontend / DeleteAccount / subscribers.js View on Github external
export default (subscribe) => {
  const deleteAccountRequested$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_REQUESTED');
  const deleteAccountSuccess$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_SUCCESS');
  const deleteAccountFailed$ = main$.filter(({ action }) => action.type === 'DELETE_ACCOUNT_FAILED');

  subscribe(deleteAccountRequested$, async ({ dispatch }) => {
    const confirmed = await dispatch(showModal({
      message: 'user.delete_account_confirm',
      title: null,
    }));
    if (confirmed) {
      deleteAccountAction()(dispatch);
    }
  });

  subscribe(deleteAccountSuccess$, ({ dispatch }) => {
    dispatch({
      type: 'TOGGLE_NAV_DRAWER',
      active: false,
github shopgate / pwa / search / streams / index.js View on Github external
* This source code is licensed under the Apache 2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { main$ } from '@shopgate/pwa-common/streams/main';
import {
  REQUEST_SEARCH_RESULTS,
  RECEIVE_SEARCH_RESULTS,
  ERROR_SEARCH_RESULTS,
} from '../constants';

/**
 * Gets triggered when search results are requested.
 * @type {Observable}
 */
export const searchRequesting$ = main$.filter(({ action }) => (
  action.type === REQUEST_SEARCH_RESULTS
));

/**
 * Gets triggered when search results are received.
 * @type {Observable}
 */
export const searchReceived$ = main$.filter(({ action }) => (
  action.type === RECEIVE_SEARCH_RESULTS ||
  action.type === ERROR_SEARCH_RESULTS
));
github shopgate / pwa / libraries / commerce / favorites / streams / index.js View on Github external
].includes(action.type));

export const shouldFetchFavorites$ = favoritesWillEnter$.merge(appDidStart$);

export const shouldFetchFreshFavorites$ = userDidLogin$.merge(userDidLogout$);

export const favoritesDidUpdate$ = main$.filter(({ action }) => [
  REQUEST_ADD_FAVORITES,
  REQUEST_REMOVE_FAVORITES,
  RECEIVE_FAVORITES,
  RECEIVE_SYNC_FAVORITES,
  ERROR_SYNC_FAVORITES,
  ERROR_FETCH_FAVORITES,
].includes(action.type));

export const favoritesWillRemoveItem$ = main$
  .filter(({ action }) => action.type === REQUEST_REMOVE_FAVORITES && !action.silent);

export const favoritesSyncIdle$ = main$.filter(({ action }) => action.type === IDLE_SYNC_FAVORITES);
github shopgate / pwa / libraries / tracking / streams / product.js View on Github external
import 'rxjs/add/operator/switchMap';
import { main$ } from '@shopgate/pwa-common/streams/main';
import { routeWillEnter$ } from '@shopgate/pwa-common/streams/router';
import { pwaDidAppear$ } from '@shopgate/pwa-common/streams/app';
import { receivedVisibleProduct$ } from '@shopgate/pwa-common-commerce/product/streams';
import {
  RECEIVE_PRODUCTS,
  ITEM_PATTERN,
} from '@shopgate/pwa-common-commerce/product/constants';

/**
 * Emits when product results has been received.
 */
export const productsReceived$ = main$
  .filter(({ action }) => action.type === RECEIVE_PRODUCTS);

/**
 * Emits when the category route comes active again after a legacy page was active.
 */
export const productRouteReappeared$ = pwaDidAppear$
  .filter(({ action }) => action.route.pattern === ITEM_PATTERN);

/**
 * Emits when a product page was initially opened.
 */
export const productWillEnter$ = routeWillEnter$
  .filter(({ action }) => action.route.pattern === ITEM_PATTERN);

/**
 * Emits when a product page was initially opened and its data is present.
github shopgate / pwa / reviews / streams / index.js View on Github external
[RECEIVE_SUBMIT_REVIEW, ERROR_SUBMIT_REVIEW, RESET_SUBMIT_REVIEW].includes(action.type)
);

/**
 * Gets triggered when the user submit was successful.
 * @type {Observable}
 */
export const successReviewSubmit$ = main$.filter(
  ({ action }) => action.type === RECEIVE_SUBMIT_REVIEW
);

/**
 * Gets triggered when the user submit was not successful.
 * @type {Observable}
 */
export const errorReviewSubmit$ = main$.filter(
  ({ action }) =>
    [ERROR_SUBMIT_REVIEW, RESET_SUBMIT_REVIEW].includes(action.type)
);
github shopgate / pwa / themes / theme-gmd / pages / Page / streams.js View on Github external
import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
import { routeWillEnter$ } from '@shopgate/pwa-common/streams/router';
import { main$ } from '@shopgate/pwa-common/streams/main';
import { RECEIVE_PAGE_CONFIG } from '@shopgate/pwa-common/constants/ActionTypes';

export const pageWillEnter$ = routeWillEnter$
  .filter(({ action }) => !!action.route.params.pageId);

export const receivedVisiblePageConfig$ = main$
  .filter(({ action, getState }) => {
    const route = getCurrentRoute(getState());

    if (action.type !== RECEIVE_PAGE_CONFIG) {
      return false;
    }

    if (typeof action.pageId === 'undefined') {
      return false;
    }

    if (!route.params.pageId) {
      return false;
    }

    return action.pageId === route.params.pageId;
github shopgate / pwa / libraries / commerce / scanner / streams / index.js View on Github external
export const scannerDidEnter$ = routeDidEnter$
  .filter(({ action }) => action.route.pathname === SCANNER_PATH);

export const startScanner$ = main$
  .filter(({ action }) => action.type === START_SCANNER);

/** @type {Observable} */
export const scannerStarted$ = main$
  .filter(({ action }) => action.type === SCANNER_STARTED);

/** @type {Observable} */
export const scannerCancelled$ = main$
  .filter(({ action }) => action.type === SCANNER_CANCELLED);

/** @type {Observable} */
export const scannerFinished$ = main$
  .filter(({ action }) => action.type === SCANNER_FINISHED);

/** @type {Observable} */
export const scannerFinishedBarCode$ = scannerFinished$
  .filter(({ action }) => SCANNER_FORMATS_BARCODE.includes(action.format));

/** @type {Observable} */
export const scannerFinishedQrCode$ = scannerFinished$
  .filter(({ action }) => SCANNER_FORMATS_QR_CODE.includes(action.format));