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

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