Skip to content

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 angular#92
  • Loading branch information
IgorMinar committed May 7, 2015
1 parent bebb04d commit fbf7f75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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

0 comments on commit fbf7f75

Please sign in to comment.