Skip to content

Commit

Permalink
Merge pull request #50 from iharthi/fix/abort-signal-polyfilled
Browse files Browse the repository at this point in the history
Fix AbortSignal issue in after minification
  • Loading branch information
jorgenader authored Mar 4, 2019
2 parents 950fb84 + 7376a91 commit be095e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/is/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ export const isStatusCode = (statusCodes: number | number[], status: any): statu

export const isAbortSignal = (signal: any): signal is AbortSignal => {
const proto = (
signal
!!signal
&& typeof signal === 'object'
&& Object.getPrototypeOf(signal)
);
return !!(proto && proto.constructor.name === 'AbortSignal');
// Fail-safe fallback, is required to work with some browsers that do not have native implementation of AbortSignal
const isCompatible = (
!!signal
&& typeof signal.aborted !== 'undefined'
&& typeof signal.onabort !== 'undefined'
);
return !!(proto && proto.constructor.name === 'AbortSignal') || isCompatible;
};


Expand Down
1 change: 1 addition & 0 deletions packages/is/test/typeChecks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,6 @@ describe('typeChecks api', () => {

}
expect(isAbortSignal(new AbortSignal())).toEqual(true);
expect(isAbortSignal({ aborted: false, onabort: null, listeners: {} })).toEqual(true);
});
});

0 comments on commit be095e5

Please sign in to comment.