UNPKG

@shopgate/engage

Version:
9 lines 1.29 kB
import{connect}from'react-redux';import{isAndroid}from'@shopgate/pwa-common/selectors/client';import deleteProductsFromCart from'@shopgate/pwa-common-commerce/cart/actions/deleteProductsFromCart';import updateProductsInCart from'@shopgate/pwa-common-commerce/cart/actions/updateProductsInCart';import{getCurrency}from'@shopgate/pwa-common-commerce/cart/selectors';/** * Maps the contents of the state to the component props. * @param {Object} state The current application state. * @return {Object} The extended component props. */var mapStateToProps=function mapStateToProps(state){return{isAndroid:isAndroid(state),currency:getCurrency(state)};};/** * Connects the dispatch function to a callable function in the props. * @param {Function} dispatch The redux dispatch function. * @return {Object} The extended component props. */var mapDispatchToProps=function mapDispatchToProps(dispatch){return{deleteProduct:function deleteProduct(cartItemId){return dispatch(deleteProductsFromCart([cartItemId]));},updateProduct:function updateProduct(cartItemId,quantity){if(quantity===0){return dispatch(deleteProductsFromCart([cartItemId]));}return dispatch(updateProductsInCart([{cartItemId:cartItemId,quantity:quantity}]));}};};export default connect(mapStateToProps,mapDispatchToProps);