This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,11 @@ interface ZoneType {
257
257
* Verify that Zone has been correctly patched. Specifically that Promise is zone aware.
258
258
*/
259
259
assertZonePatched ( ) ;
260
+
261
+ /**
262
+ * Return the root zone.
263
+ */
264
+ root : Zone ;
260
265
}
261
266
262
267
/**
@@ -564,6 +569,13 @@ const Zone: ZoneType = (function(global: any) {
564
569
}
565
570
}
566
571
572
+ static get root ( ) : AmbientZone {
573
+ let zone = Zone . current ;
574
+ while ( zone . parent ) {
575
+ zone = zone . parent ;
576
+ }
577
+ return zone ;
578
+ }
567
579
568
580
static get current ( ) : AmbientZone {
569
581
return _currentZoneFrame . zone ;
Original file line number Diff line number Diff line change @@ -83,6 +83,30 @@ describe('Zone', function() {
83
83
} ) ;
84
84
} ) ;
85
85
86
+ describe ( 'run out side of current zone' , function ( ) {
87
+ it ( 'should be able to get root zone' , function ( ) {
88
+ Zone . current . fork ( { name : 'testZone' } ) . run ( function ( ) {
89
+ expect ( Zone . root . name ) . toEqual ( '<root>' ) ;
90
+ } ) ;
91
+ } ) ;
92
+
93
+ it ( 'should be able to get run under rootZone' , function ( ) {
94
+ Zone . current . fork ( { name : 'testZone' } ) . run ( function ( ) {
95
+ Zone . root . run ( ( ) => {
96
+ expect ( Zone . current . name ) . toEqual ( '<root>' ) ;
97
+ } ) ;
98
+ } ) ;
99
+ } ) ;
100
+
101
+ it ( 'should be able to get run outside of current zone' , function ( ) {
102
+ Zone . current . fork ( { name : 'testZone' } ) . run ( function ( ) {
103
+ Zone . root . fork ( { name : 'newTestZone' } ) . run ( ( ) => {
104
+ expect ( Zone . current . name ) . toEqual ( 'newTestZone' ) ;
105
+ expect ( Zone . current . parent . name ) . toEqual ( '<root>' ) ;
106
+ } ) ;
107
+ } ) ;
108
+ } ) ;
109
+ } ) ;
86
110
87
111
describe ( 'get' , function ( ) {
88
112
it ( 'should store properties' , function ( ) {
You can’t perform that action at this time.
0 commit comments