Skip to content

Commit 2bf5489

Browse files
38elementseddyerburgh
authored andcommitted
fix: set vuex watcher getter (#287)
1 parent 764774d commit 2bf5489

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/wrappers/wrapper.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,24 @@ export default class Wrapper implements BaseWrapper {
416416
// $FlowIgnore : Problem with possibly null this.vm
417417
this.vm._computedWatchers[key].getter = () => computed[key]
418418
} else {
419+
let isStore = false
419420
// $FlowIgnore : Problem with possibly null this.vm
420-
if (!this.vm._watchers.some(w => w.getter.name === key)) {
421+
const max = this.vm._watchers.length
422+
for (let i = 0; i < max; i++) {
423+
// $FlowIgnore : Problem with possibly null this.vm
424+
const watcher = this.vm._watchers[i]
425+
// $FlowIgnore : Problem with possibly null this.vm
426+
if (watcher.getter.vuex && key in watcher.vm.$options.store.getters) {
427+
watcher.vm.$options.store.getters = {
428+
...watcher.vm.$options.store.getters
429+
}
430+
Object.defineProperty(watcher.vm.$options.store.getters, key, { get: function () { return computed[key] } })
431+
isStore = true
432+
break
433+
}
434+
}
435+
// $FlowIgnore : Problem with possibly null this.vm
436+
if (!isStore && !this.vm._watchers.some(w => w.getter.name === key)) {
421437
throwError(`wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property ${key} does not exist on the Vue instance`)
422438
}
423439
// $FlowIgnore : Problem with possibly null this.vm

0 commit comments

Comments
 (0)