source: trip-planner-front/node_modules/zone.js/bundles/zone-patch-fetch.umd.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[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 /**
20 * @fileoverview
21 * @suppress {missingRequire}
22 */
23 Zone.__load_patch('fetch', function (global, Zone, api) {
24 var fetch = global['fetch'];
25 if (typeof fetch !== 'function') {
26 return;
27 }
28 var originalFetch = global[api.symbol('fetch')];
29 if (originalFetch) {
30 // restore unpatched fetch first
31 fetch = originalFetch;
32 }
33 var ZoneAwarePromise = global.Promise;
34 var symbolThenPatched = api.symbol('thenPatched');
35 var fetchTaskScheduling = api.symbol('fetchTaskScheduling');
36 var fetchTaskAborting = api.symbol('fetchTaskAborting');
37 var OriginalAbortController = global['AbortController'];
38 var supportAbort = typeof OriginalAbortController === 'function';
39 var abortNative = null;
40 if (supportAbort) {
41 global['AbortController'] = function () {
42 var abortController = new OriginalAbortController();
43 var signal = abortController.signal;
44 signal.abortController = abortController;
45 return abortController;
46 };
47 abortNative = api.patchMethod(OriginalAbortController.prototype, 'abort', function (delegate) { return function (self, args) {
48 if (self.task) {
49 return self.task.zone.cancelTask(self.task);
50 }
51 return delegate.apply(self, args);
52 }; });
53 }
54 var placeholder = function () { };
55 global['fetch'] = function () {
56 var _this = this;
57 var args = Array.prototype.slice.call(arguments);
58 var options = args.length > 1 ? args[1] : null;
59 var signal = options && options.signal;
60 return new Promise(function (res, rej) {
61 var task = Zone.current.scheduleMacroTask('fetch', placeholder, { fetchArgs: args }, function () {
62 var fetchPromise;
63 var zone = Zone.current;
64 try {
65 zone[fetchTaskScheduling] = true;
66 fetchPromise = fetch.apply(_this, args);
67 }
68 catch (error) {
69 rej(error);
70 return;
71 }
72 finally {
73 zone[fetchTaskScheduling] = false;
74 }
75 if (!(fetchPromise instanceof ZoneAwarePromise)) {
76 var ctor = fetchPromise.constructor;
77 if (!ctor[symbolThenPatched]) {
78 api.patchThen(ctor);
79 }
80 }
81 fetchPromise.then(function (resource) {
82 if (task.state !== 'notScheduled') {
83 task.invoke();
84 }
85 res(resource);
86 }, function (error) {
87 if (task.state !== 'notScheduled') {
88 task.invoke();
89 }
90 rej(error);
91 });
92 }, function () {
93 if (!supportAbort) {
94 rej('No AbortController supported, can not cancel fetch');
95 return;
96 }
97 if (signal && signal.abortController && !signal.aborted &&
98 typeof signal.abortController.abort === 'function' && abortNative) {
99 try {
100 Zone.current[fetchTaskAborting] = true;
101 abortNative.call(signal.abortController);
102 }
103 finally {
104 Zone.current[fetchTaskAborting] = false;
105 }
106 }
107 else {
108 rej('cancel fetch need a AbortController.signal');
109 }
110 });
111 if (signal && signal.abortController) {
112 signal.abortController.task = task;
113 }
114 });
115 };
116 });
117})));
Note: See TracBrowser for help on using the repository browser.