actions.js 542 B

1234567891011121314151617181920
  1. import shop from '../api/shop'
  2. import * as types from './mutation-types'
  3. export const addToCart = types.ADD_TO_CART
  4. export const checkout = ({ dispatch, state }, products) => {
  5. const savedCartItems = [...state.cart.added]
  6. dispatch(types.CHECKOUT_REQUEST)
  7. shop.buyProducts(
  8. products,
  9. () => dispatch(types.CHECKOUT_SUCCESS),
  10. () => dispatch(types.CHECKOUT_FAILURE, savedCartItems)
  11. )
  12. }
  13. export const getAllProducts = ({ dispatch }) => {
  14. shop.getProducts(products => {
  15. dispatch(types.RECEIVE_PRODUCTS, products)
  16. })
  17. }