Skip to content

Commit d1cb234

Browse files
committed
comments
1 parent 064fb14 commit d1cb234

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/override.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export default function (Vue) {
1010
_init.call(this, options)
1111
}
1212

13+
/**
14+
* Vuex init hook, injected into each instances init hooks list.
15+
*/
16+
1317
function vuexInit () {
1418
const options = this.$options
1519
const { store, vuex } = options
@@ -47,16 +51,28 @@ export default function (Vue) {
4751
if (actions) {
4852
options.methods = options.methods || {}
4953
for (let key in actions) {
50-
options.methods[key] = makeBoundAction(actions[key], this.$store)
54+
options.methods[key] = makeBoundAction(this.$store, actions[key])
5155
}
5256
}
5357
}
5458
}
5559

60+
/**
61+
* Setter for all getter properties.
62+
*/
63+
5664
function setter () {
5765
throw new Error('vuex getter properties are read-only.')
5866
}
5967

68+
/**
69+
* Define a Vuex getter on an instance.
70+
*
71+
* @param {Vue} vm
72+
* @param {String} key
73+
* @param {Function} getter
74+
*/
75+
6076
function defineVuexGetter (vm, key, getter) {
6177
Object.defineProperty(vm, key, {
6278
enumerable: true,
@@ -66,6 +82,17 @@ export default function (Vue) {
6682
})
6783
}
6884

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+
6996
function makeComputedGetter (store, getter) {
7097
const id = store._getterCacheId
7198
// cached
@@ -94,7 +121,14 @@ export default function (Vue) {
94121
return computedGetter
95122
}
96123

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) {
98132
return function vuexBoundAction (...args) {
99133
return action.call(this, store, ...args)
100134
}

0 commit comments

Comments
 (0)