| 151 | }; |
| 152 | |
| 153 | const patchSubscriber = function () { |
| 154 | const next = Subscriber.prototype.next; |
| 155 | const error = Subscriber.prototype.error; |
| 156 | const complete = Subscriber.prototype.complete; |
| 157 | |
| 158 | Object.defineProperty(Subscriber.prototype, 'destination', { |
| 159 | configurable: true, |
| 160 | get: function (this: Subscriber<any>) { |
| 161 | return (this as any)._zoneDestination; |
| 162 | }, |
| 163 | set: function (this: Subscriber<any>, destination: any) { |
| 164 | (this as any)._zone = Zone.current; |
| 165 | (this as any)._zoneDestination = destination; |
| 166 | }, |
| 167 | }); |
| 168 | |
| 169 | // patch Subscriber.next to make sure it run |
| 170 | // into SubscriptionZone |
| 171 | Subscriber.prototype.next = function (this: ZoneSubscriberContext) { |
| 172 | const currentZone = Zone.current; |
| 173 | const subscriptionZone = this._zone; |
| 174 | |
| 175 | // for performance concern, check Zone.current |
| 176 | // equal with this._zone(SubscriptionZone) or not |
| 177 | if (subscriptionZone && subscriptionZone !== currentZone) { |
| 178 | return subscriptionZone.run(next, this, arguments as any, nextSource); |
| 179 | } else { |
| 180 | return next.apply(this, arguments as any); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | Subscriber.prototype.error = function (this: ZoneSubscriberContext) { |
| 185 | const currentZone = Zone.current; |
| 186 | const subscriptionZone = this._zone; |
| 187 | |
| 188 | // for performance concern, check Zone.current |
| 189 | // equal with this._zone(SubscriptionZone) or not |
| 190 | if (subscriptionZone && subscriptionZone !== currentZone) { |
| 191 | return subscriptionZone.run(error, this, arguments as any, errorSource); |
| 192 | } else { |
| 193 | return error.apply(this, arguments as any); |
| 194 | } |
| 195 | }; |
| 196 | |
| 197 | Subscriber.prototype.complete = function (this: ZoneSubscriberContext) { |
| 198 | const currentZone = Zone.current; |
| 199 | const subscriptionZone = this._zone; |
| 200 | |
| 201 | // for performance concern, check Zone.current |
| 202 | // equal with this._zone(SubscriptionZone) or not |
| 203 | if (subscriptionZone && subscriptionZone !== currentZone) { |
| 204 | return subscriptionZone.run(complete, this, arguments as any, completeSource); |
| 205 | } else { |
| 206 | return complete.call(this); |
| 207 | } |
| 208 | }; |
| 209 | }; |
| 210 | |