[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 | /**
|
---|
| 8 | * @license
|
---|
| 9 | * Copyright Google LLC All Rights Reserved.
|
---|
| 10 | *
|
---|
| 11 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 12 | * found in the LICENSE file at https://angular.io/license
|
---|
| 13 | */
|
---|
| 14 | Zone.__load_patch('jsonp', (global, Zone, api) => {
|
---|
| 15 | // because jsonp is not a standard api, there are a lot of
|
---|
| 16 | // implementations, so zone.js just provide a helper util to
|
---|
| 17 | // patch the jsonp send and onSuccess/onError callback
|
---|
| 18 | // the options is an object which contains
|
---|
| 19 | // - jsonp, the jsonp object which hold the send function
|
---|
| 20 | // - sendFuncName, the name of the send function
|
---|
| 21 | // - successFuncName, success func name
|
---|
| 22 | // - failedFuncName, failed func name
|
---|
| 23 | Zone[Zone.__symbol__('jsonp')] = function patchJsonp(options) {
|
---|
| 24 | if (!options || !options.jsonp || !options.sendFuncName) {
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 | const noop = function () { };
|
---|
| 28 | [options.successFuncName, options.failedFuncName].forEach(methodName => {
|
---|
| 29 | if (!methodName) {
|
---|
| 30 | return;
|
---|
| 31 | }
|
---|
| 32 | const oriFunc = global[methodName];
|
---|
| 33 | if (oriFunc) {
|
---|
| 34 | api.patchMethod(global, methodName, (delegate) => (self, args) => {
|
---|
| 35 | const task = global[api.symbol('jsonTask')];
|
---|
| 36 | if (task) {
|
---|
| 37 | task.callback = delegate;
|
---|
| 38 | return task.invoke.apply(self, args);
|
---|
| 39 | }
|
---|
| 40 | else {
|
---|
| 41 | return delegate.apply(self, args);
|
---|
| 42 | }
|
---|
| 43 | });
|
---|
| 44 | }
|
---|
| 45 | else {
|
---|
| 46 | Object.defineProperty(global, methodName, {
|
---|
| 47 | configurable: true,
|
---|
| 48 | enumerable: true,
|
---|
| 49 | get: function () {
|
---|
| 50 | return function () {
|
---|
| 51 | const task = global[api.symbol('jsonpTask')];
|
---|
| 52 | const delegate = global[api.symbol(`jsonp${methodName}callback`)];
|
---|
| 53 | if (task) {
|
---|
| 54 | if (delegate) {
|
---|
| 55 | task.callback = delegate;
|
---|
| 56 | }
|
---|
| 57 | global[api.symbol('jsonpTask')] = undefined;
|
---|
| 58 | return task.invoke.apply(this, arguments);
|
---|
| 59 | }
|
---|
| 60 | else {
|
---|
| 61 | if (delegate) {
|
---|
| 62 | return delegate.apply(this, arguments);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | return null;
|
---|
| 66 | };
|
---|
| 67 | },
|
---|
| 68 | set: function (callback) {
|
---|
| 69 | this[api.symbol(`jsonp${methodName}callback`)] = callback;
|
---|
| 70 | }
|
---|
| 71 | });
|
---|
| 72 | }
|
---|
| 73 | });
|
---|
| 74 | api.patchMethod(options.jsonp, options.sendFuncName, (delegate) => (self, args) => {
|
---|
| 75 | global[api.symbol('jsonpTask')] =
|
---|
| 76 | Zone.current.scheduleMacroTask('jsonp', noop, {}, (task) => {
|
---|
| 77 | return delegate.apply(self, args);
|
---|
| 78 | }, noop);
|
---|
| 79 | });
|
---|
| 80 | };
|
---|
| 81 | });
|
---|