Skip to content

Commit

Permalink
walkaround babel
Browse files Browse the repository at this point in the history
 which not support extends bulitin
  • Loading branch information
Keillion committed Apr 20, 2022
1 parent 3a41622 commit 379d995
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mutable-promise",
"version": "1.1.9",
"version": "1.1.10",
"description": "Wrapper for Promise. Resolvable, rejectable, redirectable.",
"files": [
"/dist",
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Executor<T> = (resolve: Resolve<T>, reject: Reject) => void;

const isPromiseLike = (value:any) => (value && "object" === typeof value && "function" === typeof value.then);

class MutablePromise<T> extends Promise<T>{
class MutablePromise<T>{ //extends Promise<T>{

private _s: string;
get status(){ return this._s; }
Expand Down Expand Up @@ -48,11 +48,18 @@ class MutablePromise<T> extends Promise<T>{
resolve: Resolve<T>
reject: Reject;

// walkaround babel which can not extend builtin class
then: (onfulfilled?: (value: T) => any, onrejected?: (reason: any) => any) => Promise<any>;

constructor(executor?: PromiseLike<T> | Executor<T> | null){
let rs: Resolve<T>;
let rj: Reject;
const fn = (_rs: Resolve<T>, _rj: Reject)=>{ rs = _rs; rj = _rj; };
super(fn);
// super(fn);

// walkaround babel which can not extend builtin class
this.then = (new Promise(fn).then);

this._s = "pending";
this.resolve = (value: ResolveValue<T>)=>{
if(this.isPending){
Expand Down

0 comments on commit 379d995

Please sign in to comment.