Skip to content

Commit 9239278

Browse files
committed
fix(#1577) run throttledDigest in a non-reactive manner.
It's possible that a digest loop from one autorun function, triggers another autorun function to be ran. Before this commit, the second autorun thought it was nested in the first autorun. This has as a side effect that when the first autorun re-runs, it will stop the second autorun from running. This commit runs the digest in a non-reactive manner, which means it temporarily resets the current active tracker computation. Therefore no parent-child relation is created between the 2 autorun functions, solving this problem.
1 parent fb65e7b commit 9239278

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/modules/core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ angular.module(name, [
131131
!this.$$phase &&
132132
!this.$root.$$phase;
133133

134-
if (isDigestable) this.$digest();
134+
if (isDigestable) {
135+
// If a digest cycle in one autorun triggers another autorun,
136+
// we want to run this second autorun in a non-reactive manner.
137+
// thus preventing inner autoruns from being dependent on their parents.
138+
Tracker.nonreactive(() => this.$digest());
139+
}
135140
};
136141

137142
// Creates a promise only that the digestion cycle will be called at its fulfillment

tests/client/core.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ describe('angular-meteor.core', function() {
9090

9191
expect(stop.calledOnce).to.be.true;
9292
});
93+
94+
it('should run digest in a non-reactive manner, so autoruns triggered by the digest are not dependent on other autoruns', function() {
95+
scope.$watch('foo',function(val) {
96+
if (val) {
97+
var computation = scope.autorun(angular.noop);
98+
expect(computation._parent).to.be.null;
99+
}
100+
});
101+
102+
scope.autorun(function() {
103+
scope.foo = 'baz';
104+
});
105+
106+
});
93107
});
94108

95109
describe('subscribe()', function() {

0 commit comments

Comments
 (0)