How to use the @shopgate/pwa-common/helpers/redux.mutable 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 / search / actions / fetchSearchResults.js View on Github external
if (promise instanceof Promise) {
    promise.then((response) => {
      // Inspect the response object to determine, if it represents a search result, or an error.
      if (response && response.products && Array.isArray(response.products)) {
        // Dispatch the receive action when the response contains valid data.s
        dispatch(receiveSearchResults(searchPhrase, offset, response));
      } else {
        // If no valid data is delivered within the response the error action is dispatched.
        dispatch(errorSearchResults(searchPhrase, offset));
      }
    });
  }
};

/** @mixes {MutableFunction} */
export default mutable(fetchSearchResults);
github shopgate / pwa / libraries / commerce / cart / actions / deleteCouponsFromCart.js View on Github external
return;
      }

      dispatch(successDeleteCouponsFromCart());
    })
    .catch((error) => {
      dispatch(errorDeleteCouponsFromCart(
        couponIds,
        createPipelineErrorList(pipelines.SHOPGATE_CART_DELETE_COUPONS, error)
      ));
      logger.error(pipelines.SHOPGATE_CART_DELETE_COUPONS, error);
    });
};

/** @mixes {MutableFunction} */
export default mutable(deleteCouponsFromCart);
github shopgate / pwa / libraries / commerce / favorites / actions / toggleFavorites.js View on Github external
* Removes a product and optionally its relatives from the favorite list (debounced and buffered).
 * @mixes {MutableFunction}
 * @param {string} productId Product identifier.
 * @param {boolean} withRelatives When true relatives which are on list are also removed.
 * @returns {Function}
 */
export const removeFavorites = mutable((productId, withRelatives = false) => (dispatch) => {
  dispatch(removeProductFromFavorites(productId, withRelatives));
});

/**
 * Triggers a sync of favorites by immediately flushing buffered favorite update actions.
 * @mixes {MutableFunction}
 * @return {Function}
 */
export const requestSync = mutable(() => (dispatch) => {
  dispatch(requestFlushFavoritesBuffer());
});
github shopgate / pwa / libraries / commerce / reviews / actions / fetchUserReview.js View on Github external
.setInput({
      productId,
    })
    .dispatch();

  request
    .then(result => dispatch(receiveUserReview(productId, result)))
    .catch(() => {
      dispatch(errorUserReview(productId));
    });

  return request;
};

/** @mixes {MutableFunction} */
export default mutable(fetchUserReview);
github shopgate / pwa / libraries / commerce / product / actions / fetchProductOptions.js View on Github external
}

  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));
    });
};

/** @mixes {MutableFunction} */
export default mutable(fetchProductOptions);
github shopgate / pwa / libraries / commerce / favorites / actions / toggleFavorites.js View on Github external
import { mutable } from '@shopgate/pwa-common/helpers/redux';
import {
  addProductToFavorites,
  removeProductFromFavorites,
  requestFlushFavoritesBuffer,
} from '../action-creators';

/**
 * Adds a product to the favorite list (debounced and buffered).
 * @mixes {MutableFunction}
 * @param {string} productId Product identifier.
 * @return {Function}
 */
export const addFavorite = mutable(productId => (dispatch) => {
  dispatch(addProductToFavorites(productId));
});

/**
 * Adds a product to the favorite list (debounced and buffered).
 * @param {string} productId Product identifier.
 * @return {Function}
 * @deprecated Please use `addFavorite` instead.
 */
export const addFavorites = addFavorite;

/**
 * Removes a product and optionally its relatives from the favorite list (debounced and buffered).
 * @mixes {MutableFunction}
 * @param {string} productId Product identifier.
 * @param {boolean} withRelatives When true relatives which are on list are also removed.
github shopgate / pwa / libraries / commerce / product / actions / fetchProductDescription.js View on Github external
}

  dispatch(requestProductDescription(productId));

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_PRODUCT_DESCRIPTION)
    .setInput({ productId })
    .dispatch()
    .then(result => dispatch(receiveProductDescription(productId, result.description)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorProductDescription(productId, error.code));
    });
};

/** @mixes {MutableFunction} */
export default mutable(fetchProductDescription);
github shopgate / pwa / libraries / commerce / category / actions / fetchCategoryProducts.js View on Github external
dispatch(fetchProducts({
      cached,
      cachedTime,
      params: {
        categoryId,
        offset,
        limit,
        sort: sortOrder,
        ...params,
      },
      filters,
    }));
  };

/** @mixes {MutableFunction} */
export default mutable(fetchCategoryProducts);
github shopgate / pwa / libraries / commerce / cart / actions / addCouponsToCart.js View on Github external
dispatch(successAddCouponsToCart(couponIds));
      resolve();
    })
    .catch((error) => {
      dispatch(errorAddCouponsToCart(
        couponIds,
        createPipelineErrorList(pipelines.SHOPGATE_CART_ADD_COUPONS, error)
      ));
      logger.error(pipelines.SHOPGATE_CART_ADD_COUPONS, error);
      reject();
    });
});

/** @mixes {MutableFunction} */
export default mutable(addCouponsToCart);
github shopgate / pwa / libraries / commerce / category / actions / fetchRootCategories.js View on Github external
return;
  }

  dispatch(requestRootCategories());

  new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_ROOT_CATEGORIES)
    .dispatch()
    .then(result => dispatch(receiveRootCategories(result.categories)))
    .catch((error) => {
      logger.error(error);
      dispatch(errorRootCategories());
    });
};

/** @mixes {MutableFunction} */
export default mutable(fetchRootCategories);