| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {Observable, Subscriber, Subscription} from 'rxjs'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  | type ZoneSubscriberContext = { | 
					
						
							|  |  |  |   _zone: Zone | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  | }&Subscriber<any>; | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | (Zone as any).__load_patch('rxjs', (global: any, Zone: ZoneType, api: _ZonePrivate) => { | 
					
						
							|  |  |  |   const symbol: (symbolString: string) => string = (Zone as any).__symbol__; | 
					
						
							|  |  |  |   const nextSource = 'rxjs.Subscriber.next'; | 
					
						
							|  |  |  |   const errorSource = 'rxjs.Subscriber.error'; | 
					
						
							|  |  |  |   const completeSource = 'rxjs.Subscriber.complete'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const ObjectDefineProperties = Object.defineProperties; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const patchObservable = function() { | 
					
						
							|  |  |  |     const ObservablePrototype: any = Observable.prototype; | 
					
						
							|  |  |  |     const _symbolSubscribe = symbol('_subscribe'); | 
					
						
							|  |  |  |     const _subscribe = ObservablePrototype[_symbolSubscribe] = ObservablePrototype._subscribe; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjectDefineProperties(Observable.prototype, { | 
					
						
							|  |  |  |       _zone: {value: null, writable: true, configurable: true}, | 
					
						
							|  |  |  |       _zoneSource: {value: null, writable: true, configurable: true}, | 
					
						
							|  |  |  |       _zoneSubscribe: {value: null, writable: true, configurable: true}, | 
					
						
							|  |  |  |       source: { | 
					
						
							|  |  |  |         configurable: true, | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |         get: function(this: Observable<any>) { | 
					
						
							|  |  |  |           return (this as any)._zoneSource; | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |         set: function(this: Observable<any>, source: any) { | 
					
						
							|  |  |  |           (this as any)._zone = Zone.current; | 
					
						
							|  |  |  |           (this as any)._zoneSource = source; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       _subscribe: { | 
					
						
							|  |  |  |         configurable: true, | 
					
						
							|  |  |  |         get: function(this: Observable<any>) { | 
					
						
							|  |  |  |           if ((this as any)._zoneSubscribe) { | 
					
						
							|  |  |  |             return (this as any)._zoneSubscribe; | 
					
						
							|  |  |  |           } else if (this.constructor === Observable) { | 
					
						
							|  |  |  |             return _subscribe; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           const proto = Object.getPrototypeOf(this); | 
					
						
							|  |  |  |           return proto && proto._subscribe; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         set: function(this: Observable<any>, subscribe: any) { | 
					
						
							|  |  |  |           (this as any)._zone = Zone.current; | 
					
						
							| 
									
										
										
										
											2020-03-10 21:35:58 +09:00
										 |  |  |           if (!subscribe) { | 
					
						
							|  |  |  |             (this as any)._zoneSubscribe = subscribe; | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             (this as any)._zoneSubscribe = function(this: ZoneSubscriberContext) { | 
					
						
							|  |  |  |               if (this._zone && this._zone !== Zone.current) { | 
					
						
							|  |  |  |                 const tearDown = this._zone.run(subscribe, this, arguments as any); | 
					
						
							|  |  |  |                 if (typeof tearDown === 'function') { | 
					
						
							|  |  |  |                   const zone = this._zone; | 
					
						
							|  |  |  |                   return function(this: ZoneSubscriberContext) { | 
					
						
							|  |  |  |                     if (zone !== Zone.current) { | 
					
						
							|  |  |  |                       return zone.run(tearDown, this, arguments as any); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     return tearDown.apply(this, arguments); | 
					
						
							|  |  |  |                   }; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                   return tearDown; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } else { | 
					
						
							|  |  |  |                 return subscribe.apply(this, arguments); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2020-03-10 21:35:58 +09:00
										 |  |  |             }; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       subjectFactory: { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |         get: function() { | 
					
						
							|  |  |  |           return (this as any)._zoneSubjectFactory; | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |         set: function(factory: any) { | 
					
						
							|  |  |  |           const zone = this._zone; | 
					
						
							|  |  |  |           this._zoneSubjectFactory = function() { | 
					
						
							|  |  |  |             if (zone && zone !== Zone.current) { | 
					
						
							|  |  |  |               return zone.run(factory, this, arguments); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return factory.apply(this, arguments); | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   api.patchMethod(Observable.prototype, 'lift', (delegate: any) => (self: any, args: any[]) => { | 
					
						
							|  |  |  |     const observable: any = delegate.apply(self, args); | 
					
						
							|  |  |  |     if (observable.operator) { | 
					
						
							|  |  |  |       observable.operator._zone = Zone.current; | 
					
						
							|  |  |  |       api.patchMethod( | 
					
						
							|  |  |  |           observable.operator, 'call', | 
					
						
							|  |  |  |           (operatorDelegate: any) => (operatorSelf: any, operatorArgs: any[]) => { | 
					
						
							|  |  |  |             if (operatorSelf._zone && operatorSelf._zone !== Zone.current) { | 
					
						
							|  |  |  |               return operatorSelf._zone.run(operatorDelegate, operatorSelf, operatorArgs); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return operatorDelegate.apply(operatorSelf, operatorArgs); | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return observable; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const patchSubscription = function() { | 
					
						
							|  |  |  |     ObjectDefineProperties(Subscription.prototype, { | 
					
						
							|  |  |  |       _zone: {value: null, writable: true, configurable: true}, | 
					
						
							|  |  |  |       _zoneUnsubscribe: {value: null, writable: true, configurable: true}, | 
					
						
							|  |  |  |       _unsubscribe: { | 
					
						
							|  |  |  |         get: function(this: Subscription) { | 
					
						
							| 
									
										
										
										
											2020-05-14 00:53:53 +09:00
										 |  |  |           if ((this as any)._zoneUnsubscribe || (this as any)._zoneUnsubscribeCleared) { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |             return (this as any)._zoneUnsubscribe; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           const proto = Object.getPrototypeOf(this); | 
					
						
							|  |  |  |           return proto && proto._unsubscribe; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         set: function(this: Subscription, unsubscribe: any) { | 
					
						
							|  |  |  |           (this as any)._zone = Zone.current; | 
					
						
							| 
									
										
										
										
											2020-03-10 21:35:58 +09:00
										 |  |  |           if (!unsubscribe) { | 
					
						
							|  |  |  |             (this as any)._zoneUnsubscribe = unsubscribe; | 
					
						
							| 
									
										
										
										
											2020-05-14 00:53:53 +09:00
										 |  |  |             // In some operator such as `retryWhen`, the _unsubscribe
 | 
					
						
							|  |  |  |             // method will be set to null, so we need to set another flag
 | 
					
						
							|  |  |  |             // to tell that we should return null instead of finding
 | 
					
						
							|  |  |  |             // in the prototype chain.
 | 
					
						
							|  |  |  |             (this as any)._zoneUnsubscribeCleared = true; | 
					
						
							| 
									
										
										
										
											2020-03-10 21:35:58 +09:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2020-05-14 00:53:53 +09:00
										 |  |  |             (this as any)._zoneUnsubscribeCleared = false; | 
					
						
							| 
									
										
										
										
											2020-03-10 21:35:58 +09:00
										 |  |  |             (this as any)._zoneUnsubscribe = function() { | 
					
						
							|  |  |  |               if (this._zone && this._zone !== Zone.current) { | 
					
						
							|  |  |  |                 return this._zone.run(unsubscribe, this, arguments); | 
					
						
							|  |  |  |               } else { | 
					
						
							|  |  |  |                 return unsubscribe.apply(this, arguments); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const patchSubscriber = function() { | 
					
						
							|  |  |  |     const next = Subscriber.prototype.next; | 
					
						
							|  |  |  |     const error = Subscriber.prototype.error; | 
					
						
							|  |  |  |     const complete = Subscriber.prototype.complete; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Object.defineProperty(Subscriber.prototype, 'destination', { | 
					
						
							|  |  |  |       configurable: true, | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |       get: function(this: Subscriber<any>) { | 
					
						
							|  |  |  |         return (this as any)._zoneDestination; | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       set: function(this: Subscriber<any>, destination: any) { | 
					
						
							|  |  |  |         (this as any)._zone = Zone.current; | 
					
						
							|  |  |  |         (this as any)._zoneDestination = destination; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // patch Subscriber.next to make sure it run
 | 
					
						
							|  |  |  |     // into SubscriptionZone
 | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |     Subscriber.prototype.next = function(this: ZoneSubscriberContext) { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       const currentZone = Zone.current; | 
					
						
							|  |  |  |       const subscriptionZone = this._zone; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // for performance concern, check Zone.current
 | 
					
						
							|  |  |  |       // equal with this._zone(SubscriptionZone) or not
 | 
					
						
							|  |  |  |       if (subscriptionZone && subscriptionZone !== currentZone) { | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |         return subscriptionZone.run(next, this, arguments as any, nextSource); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return next.apply(this, arguments as any); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |     Subscriber.prototype.error = function(this: ZoneSubscriberContext) { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       const currentZone = Zone.current; | 
					
						
							|  |  |  |       const subscriptionZone = this._zone; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // for performance concern, check Zone.current
 | 
					
						
							|  |  |  |       // equal with this._zone(SubscriptionZone) or not
 | 
					
						
							|  |  |  |       if (subscriptionZone && subscriptionZone !== currentZone) { | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |         return subscriptionZone.run(error, this, arguments as any, errorSource); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return error.apply(this, arguments as any); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |     Subscriber.prototype.complete = function(this: ZoneSubscriberContext) { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       const currentZone = Zone.current; | 
					
						
							|  |  |  |       const subscriptionZone = this._zone; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // for performance concern, check Zone.current
 | 
					
						
							|  |  |  |       // equal with this._zone(SubscriptionZone) or not
 | 
					
						
							|  |  |  |       if (subscriptionZone && subscriptionZone !== currentZone) { | 
					
						
							| 
									
										
										
										
											2019-06-26 10:33:02 +02:00
										 |  |  |         return subscriptionZone.run(complete, this, arguments as any, completeSource); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return complete.call(this); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   patchObservable(); | 
					
						
							|  |  |  |   patchSubscription(); | 
					
						
							|  |  |  |   patchSubscriber(); | 
					
						
							|  |  |  | }); |