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

Commit f7badb6

Browse files
committed
feat: add onZoneCreated hook
1 parent 7acebca commit f7badb6

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

test/zone.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,40 @@ describe('Zone.patch', function () {
189189
}).toThrow();
190190
});
191191

192+
it('should fire onZoneCreeated when a zone is forked', function () {
193+
var createdSpy = jasmine.createSpy();
194+
var counter = 0;
195+
var myZone = zone.fork({
196+
onZoneCreated: function () {
197+
counter += 1;
198+
},
199+
onZoneLeave: function () {
200+
counter -= 1;
201+
}
202+
});
203+
204+
myZone.run(function () {
205+
206+
expect(counter).toBe(0);
207+
208+
setTimeout(function () {
209+
expect(counter).toBe(2);
210+
}, 0);
211+
expect(counter).toBe(1);
212+
213+
setTimeout(function () {
214+
expect(counter).toBe(1);
215+
setTimeout(function () {}, 0);
216+
expect(counter).toBe(2);
217+
}, 0);
218+
expect(counter).toBe(2);
219+
220+
jasmine.Clock.tick(1);
221+
222+
expect(counter).toBe(0);
223+
});
224+
});
225+
192226
it('should fire onError if a function run by a zone throws', function () {
193227
var errorSpy = jasmine.createSpy();
194228
var myZone = zone.fork({

zone.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Zone.prototype = {
1818
constructor: Zone,
1919

2020
fork: function (locals) {
21+
this.onZoneCreated();
2122
return new Zone(this, locals);
2223
},
2324

@@ -53,6 +54,7 @@ Zone.prototype = {
5354
},
5455

5556
onZoneEnter: function () {},
57+
onZoneCreated: function () {},
5658
onZoneLeave: function () {}
5759
};
5860

0 commit comments

Comments
 (0)