@@ -14,6 +14,9 @@ class ProxyZoneSpec implements ZoneSpec {
14
14
properties : { [ k : string ] : any } = { 'ProxyZoneSpec' : this } ;
15
15
propertyKeys : string [ ] = null ;
16
16
17
+ lastTaskState : HasTaskState = null ;
18
+ isNeedToTriggerHasTask = false ;
19
+
17
20
static get ( ) : ProxyZoneSpec {
18
21
return Zone . current . get ( 'ProxyZoneSpec' ) ;
19
22
}
@@ -35,13 +38,20 @@ class ProxyZoneSpec implements ZoneSpec {
35
38
36
39
37
40
setDelegate ( delegateSpec : ZoneSpec ) {
41
+ const isNewDelegate = this . _delegateSpec !== delegateSpec ;
38
42
this . _delegateSpec = delegateSpec ;
39
43
this . propertyKeys && this . propertyKeys . forEach ( ( key ) => delete this . properties [ key ] ) ;
40
44
this . propertyKeys = null ;
41
45
if ( delegateSpec && delegateSpec . properties ) {
42
46
this . propertyKeys = Object . keys ( delegateSpec . properties ) ;
43
47
this . propertyKeys . forEach ( ( k ) => this . properties [ k ] = delegateSpec . properties [ k ] ) ;
44
48
}
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
+ }
45
55
}
46
56
47
57
getDelegate ( ) {
@@ -53,6 +63,15 @@ class ProxyZoneSpec implements ZoneSpec {
53
63
this . setDelegate ( this . defaultSpecDelegate ) ;
54
64
}
55
65
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
+
56
75
57
76
onFork ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , zoneSpec : ZoneSpec ) :
58
77
Zone {
@@ -79,6 +98,7 @@ class ProxyZoneSpec implements ZoneSpec {
79
98
onInvoke (
80
99
parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , delegate : Function ,
81
100
applyThis : any , applyArgs : any [ ] , source : string ) : any {
101
+ this . tryTriggerHasTask ( parentZoneDelegate , currentZone , targetZone ) ;
82
102
if ( this . _delegateSpec && this . _delegateSpec . onInvoke ) {
83
103
return this . _delegateSpec . onInvoke (
84
104
parentZoneDelegate , currentZone , targetZone , delegate , applyThis , applyArgs , source ) ;
@@ -108,7 +128,8 @@ class ProxyZoneSpec implements ZoneSpec {
108
128
onInvokeTask (
109
129
parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , task : Task ,
110
130
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 ) {
112
133
return this . _delegateSpec . onInvokeTask (
113
134
parentZoneDelegate , currentZone , targetZone , task , applyThis , applyArgs ) ;
114
135
} else {
@@ -118,6 +139,7 @@ class ProxyZoneSpec implements ZoneSpec {
118
139
119
140
onCancelTask ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone , task : Task ) :
120
141
any {
142
+ this . tryTriggerHasTask ( parentZoneDelegate , currentZone , targetZone ) ;
121
143
if ( this . _delegateSpec && this . _delegateSpec . onCancelTask ) {
122
144
return this . _delegateSpec . onCancelTask ( parentZoneDelegate , currentZone , targetZone , task ) ;
123
145
} else {
@@ -126,6 +148,7 @@ class ProxyZoneSpec implements ZoneSpec {
126
148
}
127
149
128
150
onHasTask ( delegate : ZoneDelegate , current : Zone , target : Zone , hasTaskState : HasTaskState ) : void {
151
+ this . lastTaskState = hasTaskState ;
129
152
if ( this . _delegateSpec && this . _delegateSpec . onHasTask ) {
130
153
this . _delegateSpec . onHasTask ( delegate , current , target , hasTaskState ) ;
131
154
} else {
0 commit comments