Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: don't fork new zones for callbacks from the root zone
Browse files Browse the repository at this point in the history
BREAKING CHANGE: New child zones are now created only from a async task
that installed a custom zone.

Previously even without a custom zone installed (e.g.
LongStacktracesZone), we would spawn new
child zones for all asynchronous events. This is undesirable and
generally not useful.

It does not make sense for us to create new zones for callbacks from the
root zone since we care
only about callbacks from installed custom zones. This reduces the
overhead of zones.

This primarily means that LongStackTraces zone won't be able to trace
events back to Zone.init(),
but instead the starting point will be the installation of the
LongStacktracesZone. In all practical
situations this should be sufficient.

Closes #92
  • Loading branch information
IgorMinar authored and vicb committed May 8, 2015
1 parent bf925bf commit 531d0ec
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/zone-microtask.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Zone.prototype = {

bind: function (fn, skipEnqueue) {
skipEnqueue || this.enqueueTask(fn);
var zone = this.fork();
var zone = this.isRootZone() ? this : this.fork();
return function zoneBoundFn() {
return zone.run(fn, this, arguments);
};
Expand Down
2 changes: 1 addition & 1 deletion dist/zone-microtask.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Zone.prototype = {

bind: function (fn, skipEnqueue) {
skipEnqueue || this.enqueueTask(fn);
var zone = this.fork();
var zone = this.isRootZone() ? this : this.fork();
return function zoneBoundFn() {
return zone.run(fn, this, arguments);
};
Expand Down
2 changes: 1 addition & 1 deletion dist/zone.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Zone.prototype = {

bind: function (fn, skipEnqueue) {
skipEnqueue || this.enqueueTask(fn);
var zone = this.fork();
var zone = this.isRootZone() ? this : this.fork();
return function zoneBoundFn() {
return zone.run(fn, this, arguments);
};
Expand Down
24 changes: 24 additions & 0 deletions test/zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ describe('Zone', function () {
});


describe('bind', function() {

it('should execute all callbacks from root zone without forking zones', function(done) {
// using setTimeout for the test which relies on patching via bind
setTimeout(function() {
expect(zone.isRootZone()).toBe(true);
done();
});
});


it('should fork a zone for non-root zone', function(done) {
// using setTimeout for the test which relies on patching via bind
var childZone = zone.fork();
childZone.run(function() {
setTimeout(function() {
expect(zone.parent).toBe(childZone);
done();
});
});
});
});


describe('fork', function () {
it('should fork deep copy', function () {
var protoZone = { too: { deep: true } },
Expand Down

0 comments on commit 531d0ec

Please sign in to comment.