UI for Zipcoin Blue

task-tracking.js 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (factory());
  12. }(this, (function () { 'use strict';
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. /**
  21. * A `TaskTrackingZoneSpec` allows one to track all outstanding Tasks.
  22. *
  23. * This is useful in tests. For example to see which tasks are preventing a test from completing
  24. * or an automated way of releasing all of the event listeners at the end of the test.
  25. */
  26. var TaskTrackingZoneSpec = /** @class */ (function () {
  27. function TaskTrackingZoneSpec() {
  28. this.name = 'TaskTrackingZone';
  29. this.microTasks = [];
  30. this.macroTasks = [];
  31. this.eventTasks = [];
  32. this.properties = { 'TaskTrackingZone': this };
  33. }
  34. TaskTrackingZoneSpec.get = function () {
  35. return Zone.current.get('TaskTrackingZone');
  36. };
  37. TaskTrackingZoneSpec.prototype.getTasksFor = function (type) {
  38. switch (type) {
  39. case 'microTask':
  40. return this.microTasks;
  41. case 'macroTask':
  42. return this.macroTasks;
  43. case 'eventTask':
  44. return this.eventTasks;
  45. }
  46. throw new Error('Unknown task format: ' + type);
  47. };
  48. TaskTrackingZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  49. task['creationLocation'] = new Error("Task '" + task.type + "' from '" + task.source + "'.");
  50. var tasks = this.getTasksFor(task.type);
  51. tasks.push(task);
  52. return parentZoneDelegate.scheduleTask(targetZone, task);
  53. };
  54. TaskTrackingZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  55. var tasks = this.getTasksFor(task.type);
  56. for (var i = 0; i < tasks.length; i++) {
  57. if (tasks[i] == task) {
  58. tasks.splice(i, 1);
  59. break;
  60. }
  61. }
  62. return parentZoneDelegate.cancelTask(targetZone, task);
  63. };
  64. TaskTrackingZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
  65. if (task.type === 'eventTask')
  66. return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
  67. var tasks = this.getTasksFor(task.type);
  68. for (var i = 0; i < tasks.length; i++) {
  69. if (tasks[i] == task) {
  70. tasks.splice(i, 1);
  71. break;
  72. }
  73. }
  74. return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
  75. };
  76. TaskTrackingZoneSpec.prototype.clearEvents = function () {
  77. while (this.eventTasks.length) {
  78. Zone.current.cancelTask(this.eventTasks[0]);
  79. }
  80. };
  81. return TaskTrackingZoneSpec;
  82. }());
  83. // Export the class so that new instances can be created with proper
  84. // constructor params.
  85. Zone['TaskTrackingZoneSpec'] = TaskTrackingZoneSpec;
  86. })));