Skip to content

Commit

Permalink
Reworked decorators system;
Browse files Browse the repository at this point in the history
Reworked assertion type system;
Added `@done` decorator;
Added `@ReactComponent` decorator;
Added passing arguments to the `finally` method;
Fixed a bug with return value ignoring of the `catch` method when `filter` options was set;
Added support for `CanceledError#rethrow` method to recognize CanceledErrors from another version of the package;
Added `repeatedly` option for `AbortControllerEx` constructor to support reusable internal controllers for decorated classes;
Added `version` and `versionNumber` static props to `CPromise` and `CanceledError` constructors;
Added React playground;
  • Loading branch information
DigitalBrainJS committed Apr 26, 2021
1 parent fb646cb commit f50ff58
Show file tree
Hide file tree
Showing 20 changed files with 45,057 additions and 5,152 deletions.
294 changes: 284 additions & 10 deletions README.md

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions lib/abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const _signal = Symbol('signal');
const _aborted = Symbol('aborted');
const _events = Symbol('events');
const _abort = Symbol('abort');
const _repeatedly = Symbol('repeatedly');

const nativeAbortController= (()=>{
try {
Expand All @@ -25,14 +26,15 @@ const nativeAbortController= (()=>{
* @alias CPromise.AbortSignalPolyfill
*/

class AbortSignal {
const AbortSignal= class AbortSignal {
/**
* Constructs a new AbortSignal instance
*/

constructor() {
constructor(repeatedly) {
this[_events] = {};
this[_aborted] = false;
this[_repeatedly]= repeatedly;
}

/**
Expand Down Expand Up @@ -115,31 +117,44 @@ class AbortSignal {
}

[_abort](reason) {
if(this[_repeatedly]){
this.dispatchEvent('abort', reason);
return;
}
if (this[_aborted]) return;
this[_aborted] = true;
this.dispatchEvent('abort', reason);
this[_events] = null;
}

clear(){
this[_events]= {};
}

get [Symbol.toStringTag]() {
return 'AbortSignal'
}

get repeatedly(){
return this[_repeatedly]
}

toString() {
return '[object AbortSignalPolyfill]'
return '[object AbortSignal]'
}
}

/**
* AbortController class
*/

class AbortController {
const AbortController= class AbortController {
/**
* Constructs new AbortController instance
*/
constructor() {
constructor(repeatedly) {
this[_signal] = null;
this[_repeatedly]= !!repeatedly;
}

/**
Expand All @@ -148,7 +163,7 @@ class AbortController {
*/

get signal() {
return this[_signal] || (this[_signal] = new AbortSignal());
return this[_signal] || (this[_signal] = new AbortSignal(this[_repeatedly]));
}

set signal(v) {
Expand Down
Loading

0 comments on commit f50ff58

Please sign in to comment.