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

Commit bf925bf

Browse files
IgorMinarvicb
authored andcommitted
feat: add isRootZone api
For now I'm not documenting this api. I think it generally useful and harmless enough that it could be a public api.
1 parent 038bdd9 commit bf925bf

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

dist/zone-microtask.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ browserPatch.apply();
2727
function Zone(parentZone, data) {
2828
var zone = (arguments.length) ? Object.create(parentZone) : this;
2929

30-
zone.parent = parentZone;
30+
zone.parent = parentZone || null;
3131

3232
Object.keys(data || {}).forEach(function(property) {
3333

@@ -98,6 +98,10 @@ Zone.prototype = {
9898
});
9999
},
100100

101+
isRootZone: function() {
102+
return this.parent === null;
103+
},
104+
101105
run: function run (fn, applyTo, applyWith) {
102106
applyWith = applyWith || [];
103107

dist/zone-microtask.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/zone.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ browserPatch.apply();
2222
function Zone(parentZone, data) {
2323
var zone = (arguments.length) ? Object.create(parentZone) : this;
2424

25-
zone.parent = parentZone;
25+
zone.parent = parentZone || null;
2626

2727
Object.keys(data || {}).forEach(function(property) {
2828

@@ -93,6 +93,10 @@ Zone.prototype = {
9393
});
9494
},
9595

96+
isRootZone: function() {
97+
return this.parent === null;
98+
},
99+
96100
run: function run (fn, applyTo, applyWith) {
97101
applyWith = applyWith || [];
98102

dist/zone.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function Zone(parentZone, data) {
44
var zone = (arguments.length) ? Object.create(parentZone) : this;
55

6-
zone.parent = parentZone;
6+
zone.parent = parentZone || null;
77

88
Object.keys(data || {}).forEach(function(property) {
99

@@ -74,6 +74,10 @@ Zone.prototype = {
7474
});
7575
},
7676

77+
isRootZone: function() {
78+
return this.parent === null;
79+
},
80+
7781
run: function run (fn, applyTo, applyWith) {
7882
applyWith = applyWith || [];
7983

test/zone.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ describe('Zone', function () {
129129
});
130130

131131

132+
describe('isRootZone', function() {
133+
134+
it('should return true for root zone', function() {
135+
expect(zone.isRootZone()).toBe(true);
136+
});
137+
138+
139+
it('should return false for non-root zone', function() {
140+
var executed = false;
141+
142+
zone.fork().run(function() {
143+
executed = true;
144+
expect(zone.isRootZone()).toBe(false);
145+
});
146+
147+
expect(executed).toBe(true);
148+
});
149+
});
150+
151+
132152
describe('fork', function () {
133153
it('should fork deep copy', function () {
134154
var protoZone = { too: { deep: true } },

0 commit comments

Comments
 (0)