@@ -700,14 +700,37 @@ const Zone: ZoneType = (function(global: any) {
700
700
if ( _mode === 'normal' ) {
701
701
patches [ name ] = fn ( global , Zone , _api ) ;
702
702
} else {
703
- patches [ name ] = function ( ) {
703
+ patches [ name ] = function ( ) {
704
704
fn ( global , Zone , _api ) ;
705
705
} ;
706
706
}
707
707
performanceMeasure ( perfName , perfName ) ;
708
708
}
709
709
}
710
710
711
+ static __load ( ) {
712
+ Object . keys ( patches ) . forEach ( key => patches [ key ] ( ) ) ;
713
+ patchLoaded = true ;
714
+ }
715
+
716
+ static __register_patched_delegate ( proto : any , property : string , origin : any ) {
717
+ delegates . push ( { proto : proto , property : property , patched : proto [ property ] , origin : origin } ) ;
718
+ }
719
+
720
+ static __reloadAll ( ) {
721
+ delegates . forEach ( delegate => {
722
+ delegate . proto [ delegate . property ] = delegate . patched ;
723
+ } ) ;
724
+ patchLoaded = true ;
725
+ }
726
+
727
+ static __unloadAll ( ) {
728
+ delegates . forEach ( delegate => {
729
+ delegate . proto [ delegate . property ] = delegate . origin ;
730
+ } ) ;
731
+ patchLoaded = false ;
732
+ }
733
+
711
734
public get parent ( ) : AmbientZone | null {
712
735
return this . _parent ;
713
736
}
@@ -765,18 +788,28 @@ const Zone: ZoneType = (function(global: any) {
765
788
public run ( callback : Function , applyThis ?: any , applyArgs ?: any [ ] , source ?: string ) : any ;
766
789
public run < T > (
767
790
callback : ( ...args : any [ ] ) => T , applyThis ?: any , applyArgs ?: any [ ] , source ?: string ) : T {
791
+ if ( ! patchLoaded && _mode === 'lazy' ) {
792
+ Zone . __reloadAll ( ) ;
793
+ }
768
794
_currentZoneFrame = { parent : _currentZoneFrame , zone : this } ;
769
795
try {
770
796
return this . _zoneDelegate . invoke ( this , callback , applyThis , applyArgs , source ) ;
771
797
} finally {
772
798
_currentZoneFrame = _currentZoneFrame . parent ! ;
799
+ if ( _mode === 'lazy' && _currentZoneFrame . zone &&
800
+ _currentZoneFrame . zone . name === '<root>' ) {
801
+ Zone . __unloadAll ( ) ;
802
+ }
773
803
}
774
804
}
775
805
776
806
public runGuarded ( callback : Function , applyThis ?: any , applyArgs ?: any [ ] , source ?: string ) : any ;
777
807
public runGuarded < T > (
778
808
callback : ( ...args : any [ ] ) => T , applyThis : any = null , applyArgs ?: any [ ] ,
779
809
source ?: string ) {
810
+ if ( ! patchLoaded && _mode === 'lazy' ) {
811
+ Zone . __reloadAll ( ) ;
812
+ }
780
813
_currentZoneFrame = { parent : _currentZoneFrame , zone : this } ;
781
814
try {
782
815
try {
@@ -788,6 +821,10 @@ const Zone: ZoneType = (function(global: any) {
788
821
}
789
822
} finally {
790
823
_currentZoneFrame = _currentZoneFrame . parent ! ;
824
+ if ( _mode === 'lazy' && _currentZoneFrame . zone &&
825
+ _currentZoneFrame . zone . name === '<root>' ) {
826
+ Zone . __unloadAll ( ) ;
827
+ }
791
828
}
792
829
}
793
830
@@ -811,6 +848,9 @@ const Zone: ZoneType = (function(global: any) {
811
848
task . runCount ++ ;
812
849
const previousTask = _currentTask ;
813
850
_currentTask = task ;
851
+ if ( ! patchLoaded && _mode === 'lazy' ) {
852
+ Zone . __reloadAll ( ) ;
853
+ }
814
854
_currentZoneFrame = { parent : _currentZoneFrame , zone : this } ;
815
855
try {
816
856
if ( task . type == macroTask && task . data && ! task . data . isPeriodic ) {
@@ -838,6 +878,10 @@ const Zone: ZoneType = (function(global: any) {
838
878
}
839
879
_currentZoneFrame = _currentZoneFrame . parent ! ;
840
880
_currentTask = previousTask ;
881
+ if ( _mode === 'lazy' && _currentZoneFrame . zone &&
882
+ _currentZoneFrame . zone . name === '<root>' ) {
883
+ Zone . __unloadAll ( ) ;
884
+ }
841
885
}
842
886
}
843
887
@@ -1337,6 +1381,8 @@ const Zone: ZoneType = (function(global: any) {
1337
1381
eventTask : 'eventTask' = 'eventTask' ;
1338
1382
1339
1383
const patches : { [ key : string ] : any } = { } ;
1384
+ const delegates : { proto : any , property : string , patched : any , origin : any } [ ] = [ ] ;
1385
+ let patchLoaded = false ;
1340
1386
const _api : _ZonePrivate = {
1341
1387
symbol : __symbol__ ,
1342
1388
currentZoneFrame : ( ) => _currentZoneFrame ,
@@ -1361,7 +1407,7 @@ const Zone: ZoneType = (function(global: any) {
1361
1407
let _currentZoneFrame : _ZoneFrame = { parent : null , zone : new Zone ( null , null ) } ;
1362
1408
let _currentTask : Task | null = null ;
1363
1409
let _numberOfNestedTaskFrames = 0 ;
1364
- let _mode : 'lazy' | 'normal' = 'normal' ;
1410
+ let _mode : 'lazy' | 'normal' = 'normal' ;
1365
1411
1366
1412
function noop ( ) { }
1367
1413
0 commit comments