-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathActionCreators.js
47 lines (40 loc) · 1 KB
/
ActionCreators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import ActionTypes from '../constants/ActionTypes';
import shop from '../../../common/api/shop';
export function getAllProducts() {
return (dispatch, getState) => {
dispatch({
type: ActionTypes.GET_ALL_PRODUCTS
});
shop.getProducts((products) => {
dispatch(receiveProducts(products));
});
};
}
export function receiveProducts(products) {
return {
type: ActionTypes.RECEIVE_PRODUCTS,
products: products
};
}
export function addToCart(product) {
return {
type: ActionTypes.ADD_TO_CART,
product: product
};
}
export function beginCheckout(products) {
return (dispatch, getState) => {
dispatch({
type: ActionTypes.BEGIN_CHECKOUT
});
shop.buyProducts(products, () => {
dispatch(finishCheckout(products));
});
};
}
export function finishCheckout(products) {
return {
type: ActionTypes.SUCCESS_CHECKOUT,
products: products
};
}