@@ -14,6 +14,9 @@ class ProxyZoneSpec implements ZoneSpec {
1414 properties : { [ k : string ] : any } = { 'ProxyZoneSpec' : this } ;
1515 propertyKeys : string [ ] = null ;
1616
17+ lastTaskState : HasTaskState = null ;
18+ isNeedToTriggerHasTask = false ;
19+
1720 static get ( ) : ProxyZoneSpec {
1821 return Zone . current . get ( 'ProxyZoneSpec' ) ;
1922 }
@@ -35,13 +38,20 @@ class ProxyZoneSpec implements ZoneSpec {
3538
3639
3740 setDelegate ( delegateSpec : ZoneSpec ) {
41+ const isNewDelegate = this . _delegateSpec !== delegateSpec ;
3842 this . _delegateSpec = delegateSpec ;
3943 this . propertyKeys && this . propertyKeys . forEach ( ( key ) => delete this . properties [ key ] ) ;
4044 this . propertyKeys = null ;
4145 if ( delegateSpec && delegateSpec . properties ) {
4246 this . propertyKeys = Object . keys ( delegateSpec . properties ) ;
4347 this . propertyKeys . forEach ( ( k ) => this . properties [ k ] = delegateSpec . properties [ k ] ) ;
4448 }
49+ // if set a new delegateSpec, shoulde check whether need to
50+ // trigger hasTask or not
51+ if ( isNewDelegate && this . lastTaskState &&
52+ ( this . lastTaskState . macroTask || this . lastTaskState . microTask ) ) {
53+ this . isNeedToTriggerHasTask = true ;
54+ }
4555 }
4656
4757 getDelegate ( ) {
@@ -53,6 +63,15 @@ class ProxyZoneSpec implements ZoneSpec {
5363 this . setDelegate ( this . defaultSpecDelegate ) ;
5464 }
5565
66+ tryTriggerHasTask ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone ) {
67+ if ( this . isNeedToTriggerHasTask && this . lastTaskState ) {
68+ // last delegateSpec has microTask or macroTask
69+ // should call onHasTask in current delegateSpec
70+ this . isNeedToTriggerHasTask = false ;
71+ this . onHasTask ( parentZoneDelegate , currentZone , targetZone , this . lastTaskState ) ;
72+ }
73+ }
74+
5675
5776 onFork ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , zoneSpec : ZoneSpec ) :
5877 Zone {
@@ -79,6 +98,7 @@ class ProxyZoneSpec implements ZoneSpec {
7998 onInvoke (
8099 parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , delegate : Function ,
81100 applyThis : any , applyArgs : any [ ] , source : string ) : any {
101+ this . tryTriggerHasTask ( parentZoneDelegate , currentZone , targetZone ) ;
82102 if ( this . _delegateSpec && this . _delegateSpec . onInvoke ) {
83103 return this . _delegateSpec . onInvoke (
84104 parentZoneDelegate , currentZone , targetZone , delegate , applyThis , applyArgs , source ) ;
@@ -108,7 +128,8 @@ class ProxyZoneSpec implements ZoneSpec {
108128 onInvokeTask (
109129 parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , task : Task ,
110130 applyThis : any , applyArgs : any ) : any {
111- if ( this . _delegateSpec && this . _delegateSpec . onFork ) {
131+ this . tryTriggerHasTask ( parentZoneDelegate , currentZone , targetZone ) ;
132+ if ( this . _delegateSpec && this . _delegateSpec . onInvokeTask ) {
112133 return this . _delegateSpec . onInvokeTask (
113134 parentZoneDelegate , currentZone , targetZone , task , applyThis , applyArgs ) ;
114135 } else {
@@ -118,6 +139,7 @@ class ProxyZoneSpec implements ZoneSpec {
118139
119140 onCancelTask ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , task : Task ) :
120141 any {
142+ this . tryTriggerHasTask ( parentZoneDelegate , currentZone , targetZone ) ;
121143 if ( this . _delegateSpec && this . _delegateSpec . onCancelTask ) {
122144 return this . _delegateSpec . onCancelTask ( parentZoneDelegate , currentZone , targetZone , task ) ;
123145 } else {
@@ -126,6 +148,7 @@ class ProxyZoneSpec implements ZoneSpec {
126148 }
127149
128150 onHasTask ( delegate : ZoneDelegate , current : Zone , target : Zone , hasTaskState : HasTaskState ) : void {
151+ this . lastTaskState = hasTaskState ;
129152 if ( this . _delegateSpec && this . _delegateSpec . onHasTask ) {
130153 this . _delegateSpec . onHasTask ( delegate , current , target , hasTaskState ) ;
131154 } else {
0 commit comments