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
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.

Closes angular#92
  • Loading branch information
IgorMinar committed May 2, 2015
1 parent bebb04d commit 0b13539
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 0b13539

Please sign in to comment.