Skip to content

Commit 49553f0

Browse files
committed
Wrap useTracker in Tracker.nonreactive
This was suggested by @CaptainN in meteor-svelte/svelte-tracker#3, so that the computation isn't automatically invalidated if the component is created inside a Tracker computation. I haven't yet thought through the implications of what happens if someone uses useTracker recursively.
1 parent 9a20df9 commit 49553f0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

use-tracker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
export default function useTracker(reactiveFn) {
66
return {
77
subscribe(set) {
8-
const computation = Tracker.autorun(() => set(reactiveFn()));
9-
return computation.stop.bind(computation);
8+
return Tracker.nonreactive(() => {
9+
const computation = Tracker.autorun(() => set(reactiveFn()));
10+
return computation.stop.bind(computation);
11+
});
1012
},
1113
};
1214
};

0 commit comments

Comments
 (0)