Skip to content

Commit 9692af5

Browse files
authored
Merge pull request #1592 from sebakerckhof/angular1
fix(#1577): Prevent thi…
2 parents fb65e7b + 9239278 commit 9692af5

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)