@@ -10,6 +10,10 @@ export default function (Vue) {
10
10
_init . call ( this , options )
11
11
}
12
12
13
+ /**
14
+ * Vuex init hook, injected into each instances init hooks list.
15
+ */
16
+
13
17
function vuexInit ( ) {
14
18
const options = this . $options
15
19
const { store, vuex } = options
@@ -47,16 +51,28 @@ export default function (Vue) {
47
51
if ( actions ) {
48
52
options . methods = options . methods || { }
49
53
for ( let key in actions ) {
50
- options . methods [ key ] = makeBoundAction ( actions [ key ] , this . $store )
54
+ options . methods [ key ] = makeBoundAction ( this . $store , actions [ key ] )
51
55
}
52
56
}
53
57
}
54
58
}
55
59
60
+ /**
61
+ * Setter for all getter properties.
62
+ */
63
+
56
64
function setter ( ) {
57
65
throw new Error ( 'vuex getter properties are read-only.' )
58
66
}
59
67
68
+ /**
69
+ * Define a Vuex getter on an instance.
70
+ *
71
+ * @param {Vue } vm
72
+ * @param {String } key
73
+ * @param {Function } getter
74
+ */
75
+
60
76
function defineVuexGetter ( vm , key , getter ) {
61
77
Object . defineProperty ( vm , key , {
62
78
enumerable : true ,
@@ -66,6 +82,17 @@ export default function (Vue) {
66
82
} )
67
83
}
68
84
85
+ /**
86
+ * Make a computed getter, using the same caching mechanism of computed
87
+ * properties. In addition, it is cached on the raw getter function using
88
+ * the store's unique cache id. This makes the same getter shared
89
+ * across all components use the same underlying watcher, and makes
90
+ * the getter evaluated only once during every flush.
91
+ *
92
+ * @param {Store } store
93
+ * @param {Function } getter
94
+ */
95
+
69
96
function makeComputedGetter ( store , getter ) {
70
97
const id = store . _getterCacheId
71
98
// cached
@@ -94,7 +121,14 @@ export default function (Vue) {
94
121
return computedGetter
95
122
}
96
123
97
- function makeBoundAction ( action , store ) {
124
+ /**
125
+ * Make a bound-to-store version of a raw action function.
126
+ *
127
+ * @param {Store } store
128
+ * @param {Function } action
129
+ */
130
+
131
+ function makeBoundAction ( store , action ) {
98
132
return function vuexBoundAction ( ...args ) {
99
133
return action . call ( this , store , ...args )
100
134
}
0 commit comments