abortcontroller-polyfill
Advanced tools
Comparing version 1.2.0 to 1.2.1
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (parent === null) { | ||
return undefined; | ||
if (parent === null) { | ||
return undefined; | ||
} else { | ||
return get(parent, property, receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
return get(parent, property, receiver); | ||
var getter = desc.get; | ||
if (getter === undefined) { | ||
return undefined; | ||
} | ||
return getter.call(receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
var getter = desc.get; | ||
}; | ||
if (getter === undefined) { | ||
return undefined; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
return getter.call(receiver); | ||
} | ||
}; | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
this.listeners = {}; | ||
} | ||
this.listeners = {}; | ||
} | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
} | ||
} | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
this.signal = new AbortSignal(); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
this.signal = new AbortSignal(); | ||
} | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
} | ||
} | ||
this.signal.dispatchEvent(event); | ||
} | ||
this.signal.dispatchEvent(event); | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
(function (self) { | ||
(function (self) { | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
})(typeof self !== 'undefined' ? self : global); | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
})(typeof self !== 'undefined' ? self : global); | ||
}))); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (parent === null) { | ||
return undefined; | ||
if (parent === null) { | ||
return undefined; | ||
} else { | ||
return get(parent, property, receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
return get(parent, property, receiver); | ||
var getter = desc.get; | ||
if (getter === undefined) { | ||
return undefined; | ||
} | ||
return getter.call(receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
var getter = desc.get; | ||
}; | ||
if (getter === undefined) { | ||
return undefined; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
return getter.call(receiver); | ||
} | ||
}; | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
this.listeners = {}; | ||
} | ||
this.listeners = {}; | ||
} | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
} | ||
} | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
this.signal = new AbortSignal(); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
} | ||
} | ||
this.signal.dispatchEvent(event); | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
this.signal = new AbortSignal(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
} | ||
} | ||
this.signal.dispatchEvent(event); | ||
/** | ||
* Note: the "fetch.Request" default value is available for fetch imported from | ||
* the "node-fetch" package and not in browsers. This is OK since browsers | ||
* will be importing umd-polyfill.js from that path "self" is passed the | ||
* decorator so the default value will not be used (because browsers that define | ||
* fetch also has Request). One quirky setup where self.fetch exists but | ||
* self.Request does not is when the "unfetch" minimal fetch polyfill is used | ||
* on top of IE11; for this case the browser will try to use the fetch.Request | ||
* default value which in turn will be undefined but then then "if (Request)" | ||
* will ensure that you get a patched fetch but still no Request (as expected). | ||
* @param {fetch, Request = fetch.Request} | ||
* @returns {fetch: abortableFetch, Request: AbortableRequest} | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
if ('function' === typeof patchTargets) { | ||
patchTargets = { fetch: patchTargets }; | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
_patchTargets$AbortCo = _patchTargets.AbortController, | ||
NativeAbortController = _patchTargets$AbortCo === undefined ? AbortController : _patchTargets$AbortCo; | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
/** | ||
* Note: the "fetch.Request" default value is available for fetch imported from | ||
* the "node-fetch" package and not in browsers. This is OK since browsers | ||
* will be importing umd-polyfill.js from that path "self" is passed the | ||
* decorator so the default value will not be used (because browsers that define | ||
* fetch also has Request). One quirky setup where self.fetch exists but | ||
* self.Request does not is when the "unfetch" minimal fetch polyfill is used | ||
* on top of IE11; for this case the browser will try to use the fetch.Request | ||
* default value which in turn will be undefined but then then "if (Request)" | ||
* will ensure that you get a patched fetch but still no Request (as expected). | ||
* @param {fetch, Request = fetch.Request} | ||
* @returns {fetch: abortableFetch, Request: AbortableRequest} | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
if ('function' === typeof patchTargets) { | ||
patchTargets = { fetch: patchTargets }; | ||
} | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
_patchTargets$AbortCo = _patchTargets.AbortController, | ||
NativeAbortController = _patchTargets$AbortCo === undefined ? AbortController : _patchTargets$AbortCo; | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
// so the below feature detection is wrapped in if (Request) | ||
if (Request) { | ||
// Do feature detecting | ||
var controller = new NativeAbortController(); | ||
var signal = controller.signal; | ||
var request = new Request('/', { signal: signal }); | ||
// Browser already supports abortable fetch (like FF v57 and fetch-polyfill) | ||
if (request.signal) { | ||
return { fetch: fetch, Request: Request }; | ||
} | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
// so the below feature detection is wrapped in if (Request) | ||
if (Request) { | ||
// Do feature detecting | ||
var controller = new NativeAbortController(); | ||
var signal = controller.signal; | ||
var request = new Request('/', { signal: signal }); | ||
// Browser already supports abortable fetch (like FF v57 and fetch-polyfill) | ||
if (request.signal) { | ||
return { fetch: fetch, Request: Request }; | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
if (signal) { | ||
var abortError = void 0; | ||
try { | ||
abortError = new DOMException('Aborted', 'AbortError'); | ||
} catch (err) { | ||
// IE 11 does not support calling the DOMException constructor, use a | ||
// regular error object on it instead. | ||
abortError = new Error('Aborted'); | ||
abortError.name = 'AbortError'; | ||
} | ||
if (signal) { | ||
var abortError = void 0; | ||
try { | ||
abortError = new DOMException('Aborted', 'AbortError'); | ||
} catch (err) { | ||
// IE 11 does not support calling the DOMException constructor, use a | ||
// regular error object on it instead. | ||
abortError = new Error('Aborted'); | ||
abortError.name = 'AbortError'; | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
signal.addEventListener('abort', function () { | ||
return reject(abortError); | ||
}, { once: true }); | ||
}); | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
signal.addEventListener('abort', function () { | ||
return reject(abortError); | ||
}, { once: true }); | ||
}); | ||
return realFetch(input, init); | ||
}; | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
return { fetch: abortableFetch, Request: Request }; | ||
} | ||
return realFetch(input, init); | ||
}; | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
return { fetch: abortableFetch, Request: Request }; | ||
} | ||
(function (self) { | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
(function (self) { | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
if (!self.fetch) { | ||
console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
return; | ||
} | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
if (!self.fetch) { | ||
console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
return; | ||
} | ||
self.fetch = fetch; | ||
self.Request = Request; | ||
})(typeof self !== 'undefined' ? self : global); | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
self.fetch = fetch; | ||
self.Request = Request; | ||
})(typeof self !== 'undefined' ? self : global); | ||
}))); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
var get = function get(object, property, receiver) { | ||
if (object === null) object = Function.prototype; | ||
var desc = Object.getOwnPropertyDescriptor(object, property); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (desc === undefined) { | ||
var parent = Object.getPrototypeOf(object); | ||
if (parent === null) { | ||
return undefined; | ||
if (parent === null) { | ||
return undefined; | ||
} else { | ||
return get(parent, property, receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
return get(parent, property, receiver); | ||
var getter = desc.get; | ||
if (getter === undefined) { | ||
return undefined; | ||
} | ||
return getter.call(receiver); | ||
} | ||
} else if ("value" in desc) { | ||
return desc.value; | ||
} else { | ||
var getter = desc.get; | ||
}; | ||
if (getter === undefined) { | ||
return undefined; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
return getter.call(receiver); | ||
} | ||
}; | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
var Emitter = function () { | ||
function Emitter() { | ||
classCallCheck(this, Emitter); | ||
this.listeners = {}; | ||
} | ||
this.listeners = {}; | ||
} | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
createClass(Emitter, [{ | ||
key: 'addEventListener', | ||
value: function addEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
this.listeners[type] = []; | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
this.listeners[type].push(callback); | ||
} | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
}, { | ||
key: 'removeEventListener', | ||
value: function removeEventListener(type, callback) { | ||
if (!(type in this.listeners)) { | ||
return; | ||
} | ||
var stack = this.listeners[type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
if (stack[i] === callback) { | ||
stack.splice(i, 1); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
var _this = this; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
if (!(event.type in this.listeners)) { | ||
return; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
var debounce = function debounce(callback) { | ||
setTimeout(function () { | ||
return callback.call(_this, event); | ||
}); | ||
}; | ||
var stack = this.listeners[event.type]; | ||
for (var i = 0, l = stack.length; i < l; i++) { | ||
debounce(stack[i]); | ||
} | ||
return !event.defaultPrevented; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
}]); | ||
return Emitter; | ||
}(); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
var AbortSignal = function (_Emitter) { | ||
inherits(AbortSignal, _Emitter); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
function AbortSignal() { | ||
classCallCheck(this, AbortSignal); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
var _this2 = possibleConstructorReturn(this, (AbortSignal.__proto__ || Object.getPrototypeOf(AbortSignal)).call(this)); | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
_this2.aborted = false; | ||
_this2.onabort = null; | ||
return _this2; | ||
} | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
createClass(AbortSignal, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortSignal]'; | ||
} | ||
}, { | ||
key: 'dispatchEvent', | ||
value: function dispatchEvent(event) { | ||
if (event.type === 'abort') { | ||
this.aborted = true; | ||
if (typeof this.onabort === 'function') { | ||
this.onabort.call(this, event); | ||
} | ||
} | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
get(AbortSignal.prototype.__proto__ || Object.getPrototypeOf(AbortSignal.prototype), 'dispatchEvent', this).call(this, event); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
this.signal = new AbortSignal(); | ||
} | ||
}]); | ||
return AbortSignal; | ||
}(Emitter); | ||
var AbortController = function () { | ||
function AbortController() { | ||
classCallCheck(this, AbortController); | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
} | ||
} | ||
this.signal.dispatchEvent(event); | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
this.signal = new AbortSignal(); | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
createClass(AbortController, [{ | ||
key: 'abort', | ||
value: function abort() { | ||
var event = void 0; | ||
try { | ||
event = new Event('abort'); | ||
} catch (e) { | ||
if (typeof document !== 'undefined') { | ||
// For Internet Explorer 11: | ||
event = document.createEvent('Event'); | ||
event.initEvent('abort', false, false); | ||
} else { | ||
// Fallback where document isn't available: | ||
event = { | ||
type: 'abort', | ||
bubbles: false, | ||
cancelable: false | ||
}; | ||
} | ||
} | ||
this.signal.dispatchEvent(event); | ||
/** | ||
* Note: the "fetch.Request" default value is available for fetch imported from | ||
* the "node-fetch" package and not in browsers. This is OK since browsers | ||
* will be importing umd-polyfill.js from that path "self" is passed the | ||
* decorator so the default value will not be used (because browsers that define | ||
* fetch also has Request). One quirky setup where self.fetch exists but | ||
* self.Request does not is when the "unfetch" minimal fetch polyfill is used | ||
* on top of IE11; for this case the browser will try to use the fetch.Request | ||
* default value which in turn will be undefined but then then "if (Request)" | ||
* will ensure that you get a patched fetch but still no Request (as expected). | ||
* @param {fetch, Request = fetch.Request} | ||
* @returns {fetch: abortableFetch, Request: AbortableRequest} | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
if ('function' === typeof patchTargets) { | ||
patchTargets = { fetch: patchTargets }; | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return '[object AbortController]'; | ||
} | ||
}]); | ||
return AbortController; | ||
}(); | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
_patchTargets$AbortCo = _patchTargets.AbortController, | ||
NativeAbortController = _patchTargets$AbortCo === undefined ? AbortController : _patchTargets$AbortCo; | ||
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
// These are necessary to make sure that we get correct output for: | ||
// Object.prototype.toString.call(new AbortController()) | ||
AbortController.prototype[Symbol.toStringTag] = 'AbortController'; | ||
AbortSignal.prototype[Symbol.toStringTag] = 'AbortSignal'; | ||
} | ||
/** | ||
* Note: the "fetch.Request" default value is available for fetch imported from | ||
* the "node-fetch" package and not in browsers. This is OK since browsers | ||
* will be importing umd-polyfill.js from that path "self" is passed the | ||
* decorator so the default value will not be used (because browsers that define | ||
* fetch also has Request). One quirky setup where self.fetch exists but | ||
* self.Request does not is when the "unfetch" minimal fetch polyfill is used | ||
* on top of IE11; for this case the browser will try to use the fetch.Request | ||
* default value which in turn will be undefined but then then "if (Request)" | ||
* will ensure that you get a patched fetch but still no Request (as expected). | ||
* @param {fetch, Request = fetch.Request} | ||
* @returns {fetch: abortableFetch, Request: AbortableRequest} | ||
*/ | ||
function abortableFetchDecorator(patchTargets) { | ||
if ('function' === typeof patchTargets) { | ||
patchTargets = { fetch: patchTargets }; | ||
} | ||
var _patchTargets = patchTargets, | ||
fetch = _patchTargets.fetch, | ||
_patchTargets$Request = _patchTargets.Request, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
_patchTargets$AbortCo = _patchTargets.AbortController, | ||
NativeAbortController = _patchTargets$AbortCo === undefined ? AbortController : _patchTargets$AbortCo; | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
// so the below feature detection is wrapped in if (Request) | ||
if (Request) { | ||
// Do feature detecting | ||
var controller = new NativeAbortController(); | ||
var signal = controller.signal; | ||
var request = new Request('/', { signal: signal }); | ||
// Browser already supports abortable fetch (like FF v57 and fetch-polyfill) | ||
if (request.signal) { | ||
return { fetch: fetch, Request: Request }; | ||
} | ||
var Request = NativeRequest; | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
// defining window.Request, and this polyfill need to work on top of unfetch | ||
// so the below feature detection is wrapped in if (Request) | ||
if (Request) { | ||
// Do feature detecting | ||
var controller = new NativeAbortController(); | ||
var signal = controller.signal; | ||
var request = new Request('/', { signal: signal }); | ||
// Browser already supports abortable fetch (like FF v57 and fetch-polyfill) | ||
if (request.signal) { | ||
return { fetch: fetch, Request: Request }; | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
} | ||
return request; | ||
}; | ||
Request.prototype = NativeRequest.prototype; | ||
} | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
var realFetch = fetch; | ||
var abortableFetch = function abortableFetch(input, init) { | ||
var signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined; | ||
if (signal) { | ||
var abortError = void 0; | ||
try { | ||
abortError = new DOMException('Aborted', 'AbortError'); | ||
} catch (err) { | ||
// IE 11 does not support calling the DOMException constructor, use a | ||
// regular error object on it instead. | ||
abortError = new Error('Aborted'); | ||
abortError.name = 'AbortError'; | ||
} | ||
if (signal) { | ||
var abortError = void 0; | ||
try { | ||
abortError = new DOMException('Aborted', 'AbortError'); | ||
} catch (err) { | ||
// IE 11 does not support calling the DOMException constructor, use a | ||
// regular error object on it instead. | ||
abortError = new Error('Aborted'); | ||
abortError.name = 'AbortError'; | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
} | ||
// Return early if already aborted, thus avoiding making an HTTP request | ||
if (signal.aborted) { | ||
return Promise.reject(abortError); | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
signal.addEventListener('abort', function () { | ||
return reject(abortError); | ||
}, { once: true }); | ||
}); | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
// Turn an event into a promise, reject it once `abort` is dispatched | ||
var cancellation = new Promise(function (_, reject) { | ||
signal.addEventListener('abort', function () { | ||
return reject(abortError); | ||
}, { once: true }); | ||
}); | ||
return realFetch(input, init); | ||
}; | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
return Promise.race([cancellation, realFetch(input, init)]); | ||
} | ||
return { fetch: abortableFetch, Request: Request }; | ||
} | ||
return realFetch(input, init); | ||
}; | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
return { fetch: abortableFetch, Request: Request }; | ||
} | ||
(function (self) { | ||
function nativeAbortControllerIsBroken(self) { | ||
return self.navigator && (self.navigator.vendor && self.navigator.vendor.startsWith('Apple Computer') || self.navigator.userAgent && self.navigator.userAgent.match(/ (crios|gsa|fxios)\//i)); | ||
} | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
(function (self) { | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
if (self.AbortController && !nativeAbortControllerIsBroken(self)) { | ||
return; | ||
} | ||
if (!self.fetch) { | ||
console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
return; | ||
} | ||
self.AbortController = AbortController; | ||
self.AbortSignal = AbortSignal; | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
if (!self.fetch) { | ||
console.warn('fetch() is not available, cannot install abortcontroller-polyfill'); | ||
return; | ||
} | ||
self.fetch = fetch; | ||
self.Request = Request; | ||
})(typeof self !== 'undefined' ? self : global); | ||
var _abortableFetch = abortableFetchDecorator(self), | ||
fetch = _abortableFetch.fetch, | ||
Request = _abortableFetch.Request; | ||
self.fetch = fetch; | ||
self.Request = Request; | ||
})(typeof self !== 'undefined' ? self : global); | ||
}))); |
{ | ||
"name": "abortcontroller-polyfill", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Polyfill/ponyfill for the AbortController DOM API + optional patching of fetch (stub that calls catch, doesn't actually abort request).", | ||
@@ -28,14 +28,14 @@ "main": "dist/umd-polyfill.js", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"eslint": "^4.18.1", | ||
"npm-run-all": "^4.1.2", | ||
"rollup": "^0.56.2", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^5.9.0", | ||
"npm-run-all": "^4.1.5", | ||
"rollup": "^0.67.3", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"wdio-jasmine-framework": "^0.3.2", | ||
"wdio-selenium-standalone-service": "0.0.9", | ||
"wdio-spec-reporter": "^0.1.3", | ||
"webdriverio": "^4.10.2" | ||
"wdio-jasmine-framework": "^0.3.7", | ||
"wdio-selenium-standalone-service": "0.0.11", | ||
"wdio-spec-reporter": "^0.1.5", | ||
"webdriverio": "^4.14.0" | ||
} | ||
} |
56932