Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
* 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());
});
.setInput({
productId,
})
.dispatch();
request
.then(result => dispatch(receiveUserReview(productId, result)))
.catch(() => {
dispatch(errorUserReview(productId));
});
return request;
};
/** @mixes {MutableFunction} */
export default mutable(fetchUserReview);
}
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);
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.
}
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);
dispatch(fetchProducts({
cached,
cachedTime,
params: {
categoryId,
offset,
limit,
sort: sortOrder,
...params,
},
filters,
}));
};
/** @mixes {MutableFunction} */
export default mutable(fetchCategoryProducts);
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);
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);