Skip to content

Commit

Permalink
Add prettier and apply prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mo committed May 8, 2021
1 parent 7170638 commit 1dc24ff
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 107 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
trailingComma: 'es5',
singleQuote: true,
printWidth: 120,
// NOTE: tabWidth is configured as "intent size" in .editorconfig
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"detect-browser": "^5.2.0",
"eslint": "^7.17.0",
"npm-run-all": "^4.1.5",
"prettier": "2.2.1",
"rollup": "^2.36.1",
"rollup-plugin-babel": "^4.4.0",
"webdriverio": "^6.11.3"
Expand Down
23 changes: 15 additions & 8 deletions src/abortableFetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {polyfillNeeded} from './utils.js';
import { polyfillNeeded } from './utils.js';
/**
* 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
Expand All @@ -14,7 +14,7 @@ import {polyfillNeeded} from './utils.js';
*/
export default function abortableFetchDecorator(patchTargets) {
if ('function' === typeof patchTargets) {
patchTargets = {fetch: patchTargets};
patchTargets = { fetch: patchTargets };
}
const {
fetch,
Expand All @@ -23,8 +23,15 @@ export default function abortableFetchDecorator(patchTargets) {
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = false,
} = patchTargets;

if (!polyfillNeeded({fetch, Request: NativeRequest, AbortController: NativeAbortController, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL})) {
return {fetch, Request};
if (
!polyfillNeeded({
fetch,
Request: NativeRequest,
AbortController: NativeAbortController,
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,
})
) {
return { fetch, Request };
}

let Request = NativeRequest;
Expand Down Expand Up @@ -58,7 +65,7 @@ export default function abortableFetchDecorator(patchTargets) {
writable: false,
enumerable: false,
configurable: true,
value: signal
value: signal,
});
}
return request;
Expand All @@ -68,7 +75,7 @@ export default function abortableFetchDecorator(patchTargets) {

const realFetch = fetch;
const abortableFetch = (input, init) => {
const signal = (Request && Request.prototype.isPrototypeOf(input)) ? input.signal : init ? init.signal : undefined;
const signal = Request && Request.prototype.isPrototypeOf(input) ? input.signal : init ? init.signal : undefined;

if (signal) {
let abortError;
Expand All @@ -88,7 +95,7 @@ export default function abortableFetchDecorator(patchTargets) {

// Turn an event into a promise, reject it once `abort` is dispatched
const cancellation = new Promise((_, reject) => {
signal.addEventListener('abort', () => reject(abortError), {once: true});
signal.addEventListener('abort', () => reject(abortError), { once: true });
});

if (init && init.signal) {
Expand All @@ -107,5 +114,5 @@ export default function abortableFetchDecorator(patchTargets) {
return realFetch(input, init);
};

return {fetch: abortableFetch, Request};
return { fetch: abortableFetch, Request };
}
7 changes: 3 additions & 4 deletions src/abortcontroller-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AbortController, {AbortSignal} from './abortcontroller';
import {polyfillNeeded} from './utils';
import AbortController, { AbortSignal } from './abortcontroller';
import { polyfillNeeded } from './utils';

(function(self) {
(function (self) {
'use strict';

if (!polyfillNeeded(self)) {
Expand All @@ -10,5 +10,4 @@ import {polyfillNeeded} from './utils';

self.AbortController = AbortController;
self.AbortSignal = AbortSignal;

})(typeof self !== 'undefined' ? self : global);
8 changes: 5 additions & 3 deletions src/abortcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Emitter {
if (!(type in this.listeners)) {
this.listeners[type] = [];
}
this.listeners[type].push({callback, options});
this.listeners[type].push({ callback, options });
}
removeEventListener(type, callback) {
if (!(type in this.listeners)) {
Expand All @@ -31,7 +31,9 @@ class Emitter {
try {
listener.callback.call(this, event);
} catch (e) {
Promise.resolve().then(() => { throw e; });
Promise.resolve().then(() => {
throw e;
});
}
if (listener.options && listener.options.once) {
this.removeEventListener(event.type, listener.callback);
Expand Down Expand Up @@ -100,7 +102,7 @@ export class AbortController {
event = {
type: 'abort',
bubbles: false,
cancelable: false
cancelable: false,
};
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AbortController, {AbortSignal} from './abortcontroller';
import AbortController, { AbortSignal } from './abortcontroller';
import abortableFetch from './abortableFetch';
import {polyfillNeeded} from './utils';
import { polyfillNeeded } from './utils';

(function(self) {
(function (self) {
'use strict';

if (!polyfillNeeded(self)) {
Expand All @@ -14,22 +14,21 @@ import {polyfillNeeded} from './utils';
return;
}

const {fetch, Request} = abortableFetch(self);
const { fetch, Request } = abortableFetch(self);
self.fetch = fetch;
self.Request = Request;

Object.defineProperty(self, 'AbortController', {
writable: true,
enumerable: false,
configurable: true,
value: AbortController
value: AbortController,
});

Object.defineProperty(self, 'AbortSignal', {
writable: true,
enumerable: false,
configurable: true,
value: AbortSignal
value: AbortSignal,
});

})(typeof self !== 'undefined' ? self : global);
4 changes: 2 additions & 2 deletions src/ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as AbortController, AbortSignal} from './abortcontroller';
export {default as abortableFetch} from './abortableFetch';
export { default as AbortController, AbortSignal } from './abortcontroller';
export { default as abortableFetch } from './abortableFetch';
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export function polyfillNeeded(self) {
// up to and including 12.1.x has a window.AbortController present but still
// does NOT correctly implement abortable fetch:
// https://bugs.webkit.org/show_bug.cgi?id=174980#c2
return (typeof(self.Request) === 'function' && !self.Request.prototype.hasOwnProperty('signal')) || !self.AbortController;
return (
(typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal')) || !self.AbortController
);
}
Loading

0 comments on commit 1dc24ff

Please sign in to comment.