Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
});
}
subscribe(reviewsRouteDidEnter$, ({ dispatch, getState }) => {
const state = getState();
const productId = getCurrentBaseProductId(state);
if (!state.user.login.isLoggedIn) {
return;
}
// Only dispatch when review is not yet in store
dispatch(getUserReview(productId));
});
.switchMap((data) => {
const { getState } = data;
const query = getCurrentSearchQuery(getState());
// Check if products for the current route are already available within Redux.
const productsLoaded = getProductsResult(
getState(),
{ searchPhrase: query }
).totalProductCount !== null;
if (!productsLoaded) {
// Wait for incoming products if they are not available yet.
return resultsReceived$.first();
}
return Observable.of(data);
})
.merge(searchRouteReappeared$);
.switchMap((data) => {
const { action, getState } = data;
const { categoryId } = action.route.params;
// Check if products for the current route are already available within Redux.
const productsLoaded = getProductsResult(
getState(),
{ categoryId: hex2bin(categoryId) }
).totalProductCount !== null;
if (!productsLoaded) {
// Wait for incoming products if they are not available yet.
return productsReceived$.first();
}
return Observable.of(data);
});
export const addProductToCart = data => (dispatch, getState) => {
const state = getState();
// Transform the options to the required format for the pipeline request.
const options = getAddToCartOptions(state, data);
const { productId, quantity } = data;
dispatch(addProductsToCart([{
productId,
quantity,
...(options) && { options },
}]));
};
export const addProductToCart = data => (dispatch, getState) => {
const state = getState();
// Transform the options to the required format for the pipeline request.
const options = getAddToCartOptions(state, data);
const { productId, quantity } = data;
dispatch(addProductsToCart([{
productId,
quantity,
...(options) && { options },
}]));
};
subscribe(routeDidEnter(ITEM_PATH), ({ dispatch, getState }) => {
const productId = getCurrentBaseProductId(getState());
dispatch(getProduct(productId));
});
subscribe(shouldFetchReviews$, ({ dispatch, getState }) => {
const baseProductId = getCurrentBaseProductId(getState());
if (baseProductId) {
dispatch(getProductReviews(baseProductId, REVIEW_PREVIEW_COUNT));
}
});
}
(dispatch, getState) => {
const state = getState();
const currentProductId = getCurrentBaseProductId(state);
const productId = selectedVariantId || currentProductId;
if (!productId) {
return;
}
dispatch(requestProductData(productId, selectedVariantId));
dispatch(getProduct(productId));
};
const mapStateToProps = (state, props) => ({
currentReviewCount: getCurrentReviewCount(state, props),
isFetching: getReviewsFetchingState(state, props),
productId: getCurrentBaseProductId(state, props),
totalReviewCount: getReviewsTotalCount(state, props),
});