zone-patch-rxjs.umd.js 10 KB

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