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