zone-patch-rxjs-fake-async.umd.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2025 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. (function (factory) {
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. factory();
  10. })((function () {
  11. 'use strict';
  12. var ProxyZoneSpec = /** @class */ (function () {
  13. function ProxyZoneSpec(defaultSpecDelegate) {
  14. if (defaultSpecDelegate === void 0) { defaultSpecDelegate = null; }
  15. this.name = 'ProxyZone';
  16. this._delegateSpec = null;
  17. this.properties = { 'ProxyZoneSpec': this };
  18. this.propertyKeys = null;
  19. this.lastTaskState = null;
  20. this.isNeedToTriggerHasTask = false;
  21. this.tasks = [];
  22. this.defaultSpecDelegate = defaultSpecDelegate;
  23. this.setDelegate(defaultSpecDelegate);
  24. }
  25. ProxyZoneSpec.get = function () {
  26. return Zone.current.get('ProxyZoneSpec');
  27. };
  28. ProxyZoneSpec.isLoaded = function () {
  29. return ProxyZoneSpec.get() instanceof ProxyZoneSpec;
  30. };
  31. ProxyZoneSpec.assertPresent = function () {
  32. var spec = ProxyZoneSpec.get();
  33. if (spec === undefined) {
  34. throw new Error("Expected to be running in 'ProxyZone', but it was not found.");
  35. }
  36. return spec;
  37. };
  38. ProxyZoneSpec.prototype.setDelegate = function (delegateSpec) {
  39. var _this = this;
  40. var isNewDelegate = this._delegateSpec !== delegateSpec;
  41. this._delegateSpec = delegateSpec;
  42. this.propertyKeys && this.propertyKeys.forEach(function (key) { return delete _this.properties[key]; });
  43. this.propertyKeys = null;
  44. if (delegateSpec && delegateSpec.properties) {
  45. this.propertyKeys = Object.keys(delegateSpec.properties);
  46. this.propertyKeys.forEach(function (k) { return (_this.properties[k] = delegateSpec.properties[k]); });
  47. }
  48. // if a new delegateSpec was set, check if we need to trigger hasTask
  49. if (isNewDelegate &&
  50. this.lastTaskState &&
  51. (this.lastTaskState.macroTask || this.lastTaskState.microTask)) {
  52. this.isNeedToTriggerHasTask = true;
  53. }
  54. };
  55. ProxyZoneSpec.prototype.getDelegate = function () {
  56. return this._delegateSpec;
  57. };
  58. ProxyZoneSpec.prototype.resetDelegate = function () {
  59. this.getDelegate();
  60. this.setDelegate(this.defaultSpecDelegate);
  61. };
  62. ProxyZoneSpec.prototype.tryTriggerHasTask = function (parentZoneDelegate, currentZone, targetZone) {
  63. if (this.isNeedToTriggerHasTask && this.lastTaskState) {
  64. // last delegateSpec has microTask or macroTask
  65. // should call onHasTask in current delegateSpec
  66. this.isNeedToTriggerHasTask = false;
  67. this.onHasTask(parentZoneDelegate, currentZone, targetZone, this.lastTaskState);
  68. }
  69. };
  70. ProxyZoneSpec.prototype.removeFromTasks = function (task) {
  71. if (!this.tasks) {
  72. return;
  73. }
  74. for (var i = 0; i < this.tasks.length; i++) {
  75. if (this.tasks[i] === task) {
  76. this.tasks.splice(i, 1);
  77. return;
  78. }
  79. }
  80. };
  81. ProxyZoneSpec.prototype.getAndClearPendingTasksInfo = function () {
  82. if (this.tasks.length === 0) {
  83. return '';
  84. }
  85. var taskInfo = this.tasks.map(function (task) {
  86. var dataInfo = task.data &&
  87. Object.keys(task.data)
  88. .map(function (key) {
  89. return key + ':' + task.data[key];
  90. })
  91. .join(',');
  92. return "type: ".concat(task.type, ", source: ").concat(task.source, ", args: {").concat(dataInfo, "}");
  93. });
  94. var pendingTasksInfo = '--Pending async tasks are: [' + taskInfo + ']';
  95. // clear tasks
  96. this.tasks = [];
  97. return pendingTasksInfo;
  98. };
  99. ProxyZoneSpec.prototype.onFork = function (parentZoneDelegate, currentZone, targetZone, zoneSpec) {
  100. if (this._delegateSpec && this._delegateSpec.onFork) {
  101. return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec);
  102. }
  103. else {
  104. return parentZoneDelegate.fork(targetZone, zoneSpec);
  105. }
  106. };
  107. ProxyZoneSpec.prototype.onIntercept = function (parentZoneDelegate, currentZone, targetZone, delegate, source) {
  108. if (this._delegateSpec && this._delegateSpec.onIntercept) {
  109. return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source);
  110. }
  111. else {
  112. return parentZoneDelegate.intercept(targetZone, delegate, source);
  113. }
  114. };
  115. ProxyZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) {
  116. this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
  117. if (this._delegateSpec && this._delegateSpec.onInvoke) {
  118. return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source);
  119. }
  120. else {
  121. return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
  122. }
  123. };
  124. ProxyZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) {
  125. if (this._delegateSpec && this._delegateSpec.onHandleError) {
  126. return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error);
  127. }
  128. else {
  129. return parentZoneDelegate.handleError(targetZone, error);
  130. }
  131. };
  132. ProxyZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  133. if (task.type !== 'eventTask') {
  134. this.tasks.push(task);
  135. }
  136. if (this._delegateSpec && this._delegateSpec.onScheduleTask) {
  137. return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task);
  138. }
  139. else {
  140. return parentZoneDelegate.scheduleTask(targetZone, task);
  141. }
  142. };
  143. ProxyZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
  144. if (task.type !== 'eventTask') {
  145. this.removeFromTasks(task);
  146. }
  147. this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
  148. if (this._delegateSpec && this._delegateSpec.onInvokeTask) {
  149. return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs);
  150. }
  151. else {
  152. return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
  153. }
  154. };
  155. ProxyZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  156. if (task.type !== 'eventTask') {
  157. this.removeFromTasks(task);
  158. }
  159. this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
  160. if (this._delegateSpec && this._delegateSpec.onCancelTask) {
  161. return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task);
  162. }
  163. else {
  164. return parentZoneDelegate.cancelTask(targetZone, task);
  165. }
  166. };
  167. ProxyZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) {
  168. this.lastTaskState = hasTaskState;
  169. if (this._delegateSpec && this._delegateSpec.onHasTask) {
  170. this._delegateSpec.onHasTask(delegate, current, target, hasTaskState);
  171. }
  172. else {
  173. delegate.hasTask(target, hasTaskState);
  174. }
  175. };
  176. return ProxyZoneSpec;
  177. }());
  178. function patchProxyZoneSpec(Zone) {
  179. // Export the class so that new instances can be created with proper
  180. // constructor params.
  181. Zone['ProxyZoneSpec'] = ProxyZoneSpec;
  182. }
  183. patchProxyZoneSpec(Zone);
  184. }));