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