Skip to content

Commit 9abc4ae

Browse files
committed
Better check for life-cycle callbacks.
1 parent ffb6d3e commit 9abc4ae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: install.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ function isEmpty(object) {
1212
return true;
1313
}
1414

15-
// In Blaze, life-cycle callbacks are not run inside a reactive computation
16-
// but in Vue they are, so we isolate calls when inside a life-cycle callback.
15+
// In Blaze, life-cycle callbacks are not run inside a reactive computation but in Vue they are, so we isolate calls
16+
// when inside a life-cycle callback. Otherwise $autorun's computation runs only the first time, but then when the outside
17+
// reactive computation is invalidated, $autorun's computation stops. And because a life-cycle callback is not called
18+
// again, $autorun's computation is not recreated. Those life-cycle callbacks are not called from inside current vm's
19+
// main watcher, but from parent's or even ancestor's higher up. One possible check is to go over all ancestors and check
20+
// if current computation's watcher is one of ancestor's main watcher. But it seems just checking that the current
21+
// watcher is some component's main watcher is equivalent, but simpler.
1722
function isolate(vm, f) {
18-
if (Tracker.currentComputation && Tracker.currentComputation._pureWatcher && vm.$parent && vm.$parent._watcher === Tracker.currentComputation._vueWatcher) {
23+
if (Tracker.currentComputation && Tracker.currentComputation._pureWatcher && Tracker.currentComputation._vueWatcher.vm && Tracker.currentComputation._vueWatcher.vm._watcher === Tracker.currentComputation._vueWatcher) {
1924
return Tracker.nonreactive(f);
2025
}
2126
return f();

0 commit comments

Comments
 (0)