@@ -7,18 +7,18 @@ import {
7
7
8
8
// initial state
9
9
// shape: [{ id, quantity }]
10
- export const cartInitialState = {
10
+ const state = {
11
11
added : [ ] ,
12
12
lastCheckout : null
13
13
}
14
14
15
15
// mutations
16
- export const cartMutations = {
17
- [ ADD_TO_CART ] ( { cart } , productId ) {
18
- cart . lastCheckout = null
19
- const record = cart . added . find ( p => p . id === productId )
16
+ const mutations = {
17
+ [ ADD_TO_CART ] ( state , productId ) {
18
+ state . lastCheckout = null
19
+ const record = state . added . find ( p => p . id === productId )
20
20
if ( ! record ) {
21
- cart . added . push ( {
21
+ state . added . push ( {
22
22
id : productId ,
23
23
quantity : 1
24
24
} )
@@ -27,19 +27,24 @@ export const cartMutations = {
27
27
}
28
28
} ,
29
29
30
- [ CHECKOUT_REQUEST ] ( { cart } ) {
30
+ [ CHECKOUT_REQUEST ] ( state ) {
31
31
// clear cart
32
- cart . added = [ ]
33
- cart . lastCheckout = null
32
+ state . added = [ ]
33
+ state . lastCheckout = null
34
34
} ,
35
35
36
- [ CHECKOUT_SUCCESS ] ( { cart } ) {
37
- cart . lastCheckout = 'successful'
36
+ [ CHECKOUT_SUCCESS ] ( state ) {
37
+ state . lastCheckout = 'successful'
38
38
} ,
39
39
40
- [ CHECKOUT_FAILURE ] ( { cart } , savedCartItems ) {
40
+ [ CHECKOUT_FAILURE ] ( state , savedCartItems ) {
41
41
// rollback to the cart saved before sending the request
42
- cart . added = savedCartItems
43
- cart . lastCheckout = 'failed'
42
+ state . added = savedCartItems
43
+ state . lastCheckout = 'failed'
44
44
}
45
45
}
46
+
47
+ export default {
48
+ state,
49
+ mutations
50
+ }
0 commit comments