mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-10 17:33:36 +08:00
Summary: This adds https://github.com/mysticatea/abort-controller to polyfill [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). This is used to cancel requests when using `fetch`. This also updates `event-target-shim` to 5.0 to make sure we only have one version of this dependency. This updates required adding a polyfill for `console.assert` which is used by the new version. I made one based on https://github.com/gskinner/console-polyfill/blob/master/console.js#L74. The polyfill is very small, especially since we already use `event-target-shim` so I think it makes sense to include in core. Depends on #24418 so that the fetch polyfill supports the `signal` parameter. Fixes #18115 [General] [Added] - Add support for cancelling fetch requests with AbortController Pull Request resolved: https://github.com/facebook/react-native/pull/24419 Differential Revision: D14912858 Pulled By: cpojer fbshipit-source-id: 8a6402910398db51e2f3e3262f07aabdf68fcf72
41 lines
1.7 KiB
JavaScript
41 lines
1.7 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
'use strict';
|
|
|
|
const {polyfillGlobal} = require('PolyfillFunctions');
|
|
|
|
/**
|
|
* Set up XMLHttpRequest. The native XMLHttpRequest in Chrome dev tools is CORS
|
|
* aware and won't let you fetch anything from the internet.
|
|
*
|
|
* You can use this module directly, or just require InitializeCore.
|
|
*/
|
|
polyfillGlobal('XMLHttpRequest', () => require('XMLHttpRequest'));
|
|
polyfillGlobal('FormData', () => require('FormData'));
|
|
|
|
polyfillGlobal('fetch', () => require('fetch').fetch); // flowlint-line untyped-import:off
|
|
polyfillGlobal('Headers', () => require('fetch').Headers); // flowlint-line untyped-import:off
|
|
polyfillGlobal('Request', () => require('fetch').Request); // flowlint-line untyped-import:off
|
|
polyfillGlobal('Response', () => require('fetch').Response); // flowlint-line untyped-import:off
|
|
polyfillGlobal('WebSocket', () => require('WebSocket'));
|
|
polyfillGlobal('Blob', () => require('Blob'));
|
|
polyfillGlobal('File', () => require('File'));
|
|
polyfillGlobal('FileReader', () => require('FileReader'));
|
|
polyfillGlobal('URL', () => require('URL').URL); // flowlint-line untyped-import:off
|
|
polyfillGlobal('URLSearchParams', () => require('URL').URLSearchParams); // flowlint-line untyped-import:off
|
|
polyfillGlobal(
|
|
'AbortController',
|
|
() => require('abort-controller/dist/abort-controller').AbortController, // flowlint-line untyped-import:off
|
|
);
|
|
polyfillGlobal(
|
|
'AbortSignal',
|
|
() => require('abort-controller/dist/abort-controller').AbortSignal, // flowlint-line untyped-import:off
|
|
);
|