|
1 | 1 | import shop from '../api/shop' |
2 | 2 | import * as types from './mutation-types' |
3 | 3 |
|
4 | | -export const addToCart = ({ dispatch }, product) => { |
| 4 | +export const addToCart = ({ commit }, product) => { |
5 | 5 | if (product.inventory > 0) { |
6 | | - dispatch(types.ADD_TO_CART, { |
| 6 | + commit(types.ADD_TO_CART, { |
7 | 7 | id: product.id |
8 | 8 | }) |
9 | 9 | } |
10 | 10 | } |
11 | 11 |
|
12 | | -export const checkout = ({ dispatch, state }, products) => { |
| 12 | +export const checkout = ({ commit, state }, products) => { |
13 | 13 | const savedCartItems = [...state.cart.added] |
14 | | - dispatch(types.CHECKOUT_REQUEST) |
| 14 | + commit(types.CHECKOUT_REQUEST) |
15 | 15 | shop.buyProducts( |
16 | 16 | products, |
17 | | - () => dispatch(types.CHECKOUT_SUCCESS), |
18 | | - () => dispatch(types.CHECKOUT_FAILURE, { savedCartItems }) |
| 17 | + () => commit(types.CHECKOUT_SUCCESS), |
| 18 | + () => commit(types.CHECKOUT_FAILURE, { savedCartItems }) |
19 | 19 | ) |
20 | 20 | } |
21 | 21 |
|
22 | | -export const getAllProducts = ({ dispatch }) => { |
| 22 | +export const getAllProducts = ({ commit }) => { |
23 | 23 | shop.getProducts(products => { |
24 | | - dispatch(types.RECEIVE_PRODUCTS, { products }) |
| 24 | + commit(types.RECEIVE_PRODUCTS, { products }) |
25 | 25 | }) |
26 | 26 | } |
0 commit comments