Skip to content

Commit 1d0403a

Browse files
committed
Fix Tracker.autorun() inside Tracker.nonreactive() inside Svelte
1 parent dd21d30 commit 1d0403a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

autorun.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { Tracker } from 'meteor/tracker';
88
import { current_component, schedule_update, dirty_components } from 'svelte/internal';
99

1010

11-
_autorun = Tracker.autorun;
12-
Tracker.autorun = function autorun(f, options) {
11+
const _autorun = Tracker.autorun;
12+
const _nonreactive = Tracker.nonreactive;
13+
14+
function svelteAwareAutorun(f, options) {
1315
const component = current_component;
1416
const computation = _autorun.apply(this, arguments);
1517
if (component) {
@@ -18,6 +20,24 @@ Tracker.autorun = function autorun(f, options) {
1820
_autoStopComputation(computation, component);
1921
}
2022
return computation;
23+
}
24+
25+
Tracker.autorun = svelteAwareAutorun;
26+
27+
Tracker.nonreactive = function nonreactive(f) {
28+
if (current_component) {
29+
// A Tracker.autorun inside a Tracker.nonreactive should behave normally,
30+
// without the special Svelte stuff.
31+
const prevAutorun = Tracker.autorun;
32+
Tracker.autorun = _autorun;
33+
try {
34+
return _nonreactive.apply(this, arguments);
35+
} finally {
36+
Tracker.autorun = prevAutorun;
37+
}
38+
} else {
39+
return _nonreactive.apply(this, arguments);
40+
}
2141
};
2242

2343
function _autoStopComputation(computation, component) {

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'rdb:svelte-meteor-data',
3-
version: '0.2.0',
3+
version: '0.2.1',
44
summary: 'Reactively track Meteor data inside Svelte components',
55
git: 'https://github.com/rdb/svelte-meteor-data',
66
documentation: 'README.md'

0 commit comments

Comments
 (0)