How to use the @shopgate/pwa-common/helpers/redux.shouldFetchData 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 / actions / fetchCategory.js View on Github external
const fetchCategory = categoryId => (dispatch, getState) => {
  const state = getState();
  const category = state.category.categoriesById[categoryId];

  if (!shouldFetchData(category)) {
    /**
     * Child categories are maybe missing.
     * So we need to check it (check happens inside fetchCategoryChildren).
     * This is the case if we got categories from getRootCategory
    */
    dispatch(fetchCategoryChildren(categoryId));
    return;
  }

  // No data at all. So we have the fetch the category with children included
  dispatch(requestCategory(categoryId));

  new PipelineRequest('shopgate.catalog.getCategory')
    .setInput({
      categoryId,
      includeChildren: true,
github shopgate / pwa / libraries / commerce / category / actions / fetchCategory.js View on Github external
const fetchCategory = categoryId => (dispatch, getState) => {
  const state = getState();
  const category = state.category.categoriesById[categoryId];

  if (!shouldFetchData(category)) {
    /**
     * Child categories are maybe missing.
     * So we need to check it (check happens inside fetchCategoryChildren).
     * This is the case if we got categories from getRootCategory
    */
    if (category.childrenCount) {
      dispatch(fetchCategoryChildren(categoryId));
    }

    return Promise.resolve(category);
  }

  // No data at all. So we have the fetch the category with children included
  dispatch(requestCategory(categoryId));

  return new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_CATEGORY)
github shopgate / pwa / search / actions / fetchSearchSuggestions.js View on Github external
const fetchSearchSuggestions = () => (dispatch, getState) => {
  const state = getState();
  const searchPhrase = getSearchPhrase(state);
  const cachedSuggestions = getCurrentSearchSuggestionsObject(state);

  if (!shouldFetchData(cachedSuggestions)) {
    return;
  }

  dispatch(requestSearchSuggestions(searchPhrase));

  new PipelineRequest('getSearchSuggestions')
    .setInput({ searchPhrase })
    .dispatch()
    .then(({ suggestions }) => {
      dispatch(receiveSearchSuggestions(searchPhrase, removeHighlightingPlaceholders(suggestions)));
    });
};
github shopgate / pwa / libraries / commerce / product / actions / fetchProductRelations.js View on Github external
(dispatch, getState) => {
    const pipeline = SHOPGATE_CATALOG_GET_PRODUCT_RELATIONS;
    const hash = generateProductRelationsHash({
      productId,
      type,
      limit,
    });

    const currentState = getProductRelationsState(getState())[hash];
    if (!shouldFetchData(currentState, 'productIds')) {
      return null;
    }

    dispatch(requestProductRelations({ hash }));

    const request = new PipelineRequest(pipeline)
      .setInput({
        productId,
        type,
        limit,
      })
      .dispatch();

    request
      .then((payload) => {
        const { relations } = payload;
github shopgate / pwa / libraries / commerce / product / actions / fetchProductOptions.js View on Github external
const fetchProductOptions = productId => (dispatch, getState) => {
  const state = getState();
  const cachedData = state.product.optionsByProductId[productId];

  if (!shouldFetchData(cachedData)) {
    return;
  }

  dispatch(requestProductOptions(productId));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_OPTIONS)
    .setInput({ productId })
    .dispatch()
    .then(result => dispatch(receiveProductOptions(productId, result.options)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductOptions(productId, error.code));
    });
};
github shopgate / pwa / libraries / commerce / product / actions / fetchProductsById.js View on Github external
    const missingIds = productIds.filter(id => shouldFetchData(products[id]));
github shopgate / pwa / reviews / actions / getUserReview.js View on Github external
const getUserReview = productId => (dispatch, getState) => {
  const data = getState().reviews.userReviewsByProductId[productId];
  if (!shouldFetchData(data)) {
    return new Promise(resolve => resolve());
  }
  dispatch(requestUserReview(productId));
  const request = new PipelineRequest('getUserReview')
    .setHandledErrors([EUNKNOWN, EACCESS])
    .setInput({
      productId,
    })
    .dispatch();

  request
    .then(result => dispatch(receiveUserReview(productId, result)))
    .catch(() => {
      dispatch(errorUserReview(productId));
    });
github shopgate / pwa / libraries / commerce / reviews / actions / fetchUserReview.js View on Github external
const fetchUserReview = productId => (dispatch, getState) => {
  const data = getState().reviews.userReviewsByProductId[productId];
  if (!shouldFetchData(data)) {
    return new Promise(resolve => resolve());
  }
  dispatch(requestUserReview(productId));
  const request = new PipelineRequest(pipelines.SHOPGATE_USER_GET_REVIEW)
    .setErrorBlacklist([EUNKNOWN, EACCESS])
    .setInput({
      productId,
    })
    .dispatch();

  request
    .then(result => dispatch(receiveUserReview(productId, result)))
    .catch(() => {
      dispatch(errorUserReview(productId));
    });
github shopgate / pwa / libraries / commerce / product / actions / getProduct.js View on Github external
const getProduct = (productId, forceFetch = false) => (dispatch, getState) => {
  const state = getState();
  const product = getProductById(state, productId);

  if (!forceFetch && !shouldFetchData(product)) {
    if (product.productData) {
      dispatch(processProductFlags(product.productData))
        .then(() => {
          dispatch(receiveProductCached(product.productData));
        });
    }

    return;
  }

  dispatch(requestProduct(productId));

  new PipelineRequest('shopgate.catalog.getProduct')
    .setInput({ productId })
    .dispatch()
    .then((result) => {
github shopgate / pwa / libraries / commerce / product / actions / fetchProduct.js View on Github external
const fetchProduct = (productId, forceFetch = false) => (dispatch, getState) => {
  const state = getState();
  const product = getProductById(state, { productId });

  if (!forceFetch && !shouldFetchData(product)) {
    if (product.productData) {
      dispatch(receiveProductCached(product.productData));
    }

    return;
  }

  const requestParams = {
    ...configuration.get(DEFAULT_PRODUCTS_FETCH_PARAMS),
    productId,
  };

  dispatch(requestProduct(productId, forceFetch));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT)
    .setInput(requestParams)