Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
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)
))
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',
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,
* 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
));
].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);
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.
[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)
);
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;
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));