[6a3a178] | 1 | 'use strict';
|
---|
| 2 | /**
|
---|
| 3 | * @license Angular v12.0.0-next.0
|
---|
| 4 | * (c) 2010-2020 Google LLC. https://angular.io/
|
---|
| 5 | * License: MIT
|
---|
| 6 | */
|
---|
| 7 | import { Observable, Subscription, Subscriber } from 'rxjs';
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * @license
|
---|
| 11 | * Copyright Google LLC All Rights Reserved.
|
---|
| 12 | *
|
---|
| 13 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 14 | * found in the LICENSE file at https://angular.io/license
|
---|
| 15 | */
|
---|
| 16 | Zone.__load_patch('rxjs', (global, Zone, api) => {
|
---|
| 17 | const symbol = Zone.__symbol__;
|
---|
| 18 | const nextSource = 'rxjs.Subscriber.next';
|
---|
| 19 | const errorSource = 'rxjs.Subscriber.error';
|
---|
| 20 | const completeSource = 'rxjs.Subscriber.complete';
|
---|
| 21 | const ObjectDefineProperties = Object.defineProperties;
|
---|
| 22 | const patchObservable = function () {
|
---|
| 23 | const ObservablePrototype = Observable.prototype;
|
---|
| 24 | const _symbolSubscribe = symbol('_subscribe');
|
---|
| 25 | const _subscribe = ObservablePrototype[_symbolSubscribe] = ObservablePrototype._subscribe;
|
---|
| 26 | ObjectDefineProperties(Observable.prototype, {
|
---|
| 27 | _zone: { value: null, writable: true, configurable: true },
|
---|
| 28 | _zoneSource: { value: null, writable: true, configurable: true },
|
---|
| 29 | _zoneSubscribe: { value: null, writable: true, configurable: true },
|
---|
| 30 | source: {
|
---|
| 31 | configurable: true,
|
---|
| 32 | get: function () {
|
---|
| 33 | return this._zoneSource;
|
---|
| 34 | },
|
---|
| 35 | set: function (source) {
|
---|
| 36 | this._zone = Zone.current;
|
---|
| 37 | this._zoneSource = source;
|
---|
| 38 | }
|
---|
| 39 | },
|
---|
| 40 | _subscribe: {
|
---|
| 41 | configurable: true,
|
---|
| 42 | get: function () {
|
---|
| 43 | if (this._zoneSubscribe) {
|
---|
| 44 | return this._zoneSubscribe;
|
---|
| 45 | }
|
---|
| 46 | else if (this.constructor === Observable) {
|
---|
| 47 | return _subscribe;
|
---|
| 48 | }
|
---|
| 49 | const proto = Object.getPrototypeOf(this);
|
---|
| 50 | return proto && proto._subscribe;
|
---|
| 51 | },
|
---|
| 52 | set: function (subscribe) {
|
---|
| 53 | this._zone = Zone.current;
|
---|
| 54 | if (!subscribe) {
|
---|
| 55 | this._zoneSubscribe = subscribe;
|
---|
| 56 | }
|
---|
| 57 | else {
|
---|
| 58 | this._zoneSubscribe = function () {
|
---|
| 59 | if (this._zone && this._zone !== Zone.current) {
|
---|
| 60 | const tearDown = this._zone.run(subscribe, this, arguments);
|
---|
| 61 | if (typeof tearDown === 'function') {
|
---|
| 62 | const zone = this._zone;
|
---|
| 63 | return function () {
|
---|
| 64 | if (zone !== Zone.current) {
|
---|
| 65 | return zone.run(tearDown, this, arguments);
|
---|
| 66 | }
|
---|
| 67 | return tearDown.apply(this, arguments);
|
---|
| 68 | };
|
---|
| 69 | }
|
---|
| 70 | else {
|
---|
| 71 | return tearDown;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | return subscribe.apply(this, arguments);
|
---|
| 76 | }
|
---|
| 77 | };
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | },
|
---|
| 81 | subjectFactory: {
|
---|
| 82 | get: function () {
|
---|
| 83 | return this._zoneSubjectFactory;
|
---|
| 84 | },
|
---|
| 85 | set: function (factory) {
|
---|
| 86 | const zone = this._zone;
|
---|
| 87 | this._zoneSubjectFactory = function () {
|
---|
| 88 | if (zone && zone !== Zone.current) {
|
---|
| 89 | return zone.run(factory, this, arguments);
|
---|
| 90 | }
|
---|
| 91 | return factory.apply(this, arguments);
|
---|
| 92 | };
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | });
|
---|
| 96 | };
|
---|
| 97 | api.patchMethod(Observable.prototype, 'lift', (delegate) => (self, args) => {
|
---|
| 98 | const observable = delegate.apply(self, args);
|
---|
| 99 | if (observable.operator) {
|
---|
| 100 | observable.operator._zone = Zone.current;
|
---|
| 101 | api.patchMethod(observable.operator, 'call', (operatorDelegate) => (operatorSelf, operatorArgs) => {
|
---|
| 102 | if (operatorSelf._zone && operatorSelf._zone !== Zone.current) {
|
---|
| 103 | return operatorSelf._zone.run(operatorDelegate, operatorSelf, operatorArgs);
|
---|
| 104 | }
|
---|
| 105 | return operatorDelegate.apply(operatorSelf, operatorArgs);
|
---|
| 106 | });
|
---|
| 107 | }
|
---|
| 108 | return observable;
|
---|
| 109 | });
|
---|
| 110 | const patchSubscription = function () {
|
---|
| 111 | ObjectDefineProperties(Subscription.prototype, {
|
---|
| 112 | _zone: { value: null, writable: true, configurable: true },
|
---|
| 113 | _zoneUnsubscribe: { value: null, writable: true, configurable: true },
|
---|
| 114 | _unsubscribe: {
|
---|
| 115 | get: function () {
|
---|
| 116 | if (this._zoneUnsubscribe || this._zoneUnsubscribeCleared) {
|
---|
| 117 | return this._zoneUnsubscribe;
|
---|
| 118 | }
|
---|
| 119 | const proto = Object.getPrototypeOf(this);
|
---|
| 120 | return proto && proto._unsubscribe;
|
---|
| 121 | },
|
---|
| 122 | set: function (unsubscribe) {
|
---|
| 123 | this._zone = Zone.current;
|
---|
| 124 | if (!unsubscribe) {
|
---|
| 125 | this._zoneUnsubscribe = unsubscribe;
|
---|
| 126 | // In some operator such as `retryWhen`, the _unsubscribe
|
---|
| 127 | // method will be set to null, so we need to set another flag
|
---|
| 128 | // to tell that we should return null instead of finding
|
---|
| 129 | // in the prototype chain.
|
---|
| 130 | this._zoneUnsubscribeCleared = true;
|
---|
| 131 | }
|
---|
| 132 | else {
|
---|
| 133 | this._zoneUnsubscribeCleared = false;
|
---|
| 134 | this._zoneUnsubscribe = function () {
|
---|
| 135 | if (this._zone && this._zone !== Zone.current) {
|
---|
| 136 | return this._zone.run(unsubscribe, this, arguments);
|
---|
| 137 | }
|
---|
| 138 | else {
|
---|
| 139 | return unsubscribe.apply(this, arguments);
|
---|
| 140 | }
|
---|
| 141 | };
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | });
|
---|
| 146 | };
|
---|
| 147 | const patchSubscriber = function () {
|
---|
| 148 | const next = Subscriber.prototype.next;
|
---|
| 149 | const error = Subscriber.prototype.error;
|
---|
| 150 | const complete = Subscriber.prototype.complete;
|
---|
| 151 | Object.defineProperty(Subscriber.prototype, 'destination', {
|
---|
| 152 | configurable: true,
|
---|
| 153 | get: function () {
|
---|
| 154 | return this._zoneDestination;
|
---|
| 155 | },
|
---|
| 156 | set: function (destination) {
|
---|
| 157 | this._zone = Zone.current;
|
---|
| 158 | this._zoneDestination = destination;
|
---|
| 159 | }
|
---|
| 160 | });
|
---|
| 161 | // patch Subscriber.next to make sure it run
|
---|
| 162 | // into SubscriptionZone
|
---|
| 163 | Subscriber.prototype.next = function () {
|
---|
| 164 | const currentZone = Zone.current;
|
---|
| 165 | const subscriptionZone = this._zone;
|
---|
| 166 | // for performance concern, check Zone.current
|
---|
| 167 | // equal with this._zone(SubscriptionZone) or not
|
---|
| 168 | if (subscriptionZone && subscriptionZone !== currentZone) {
|
---|
| 169 | return subscriptionZone.run(next, this, arguments, nextSource);
|
---|
| 170 | }
|
---|
| 171 | else {
|
---|
| 172 | return next.apply(this, arguments);
|
---|
| 173 | }
|
---|
| 174 | };
|
---|
| 175 | Subscriber.prototype.error = function () {
|
---|
| 176 | const currentZone = Zone.current;
|
---|
| 177 | const subscriptionZone = this._zone;
|
---|
| 178 | // for performance concern, check Zone.current
|
---|
| 179 | // equal with this._zone(SubscriptionZone) or not
|
---|
| 180 | if (subscriptionZone && subscriptionZone !== currentZone) {
|
---|
| 181 | return subscriptionZone.run(error, this, arguments, errorSource);
|
---|
| 182 | }
|
---|
| 183 | else {
|
---|
| 184 | return error.apply(this, arguments);
|
---|
| 185 | }
|
---|
| 186 | };
|
---|
| 187 | Subscriber.prototype.complete = function () {
|
---|
| 188 | const currentZone = Zone.current;
|
---|
| 189 | const subscriptionZone = this._zone;
|
---|
| 190 | // for performance concern, check Zone.current
|
---|
| 191 | // equal with this._zone(SubscriptionZone) or not
|
---|
| 192 | if (subscriptionZone && subscriptionZone !== currentZone) {
|
---|
| 193 | return subscriptionZone.run(complete, this, arguments, completeSource);
|
---|
| 194 | }
|
---|
| 195 | else {
|
---|
| 196 | return complete.call(this);
|
---|
| 197 | }
|
---|
| 198 | };
|
---|
| 199 | };
|
---|
| 200 | patchObservable();
|
---|
| 201 | patchSubscription();
|
---|
| 202 | patchSubscriber();
|
---|
| 203 | });
|
---|