zone-patch-rxjs.umd.js 9.5 KB

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