mutable-promise
Advanced tools
Comparing version 1.1.11 to 1.1.12
const isPromiseLike = (value) => (value && "object" === typeof value && "function" === typeof value.then); | ||
class MutablePromise { | ||
_s = null; // null is bable walkaround? | ||
constructor(executor) { | ||
let rs; | ||
let rj; | ||
const fn = (_rs, _rj) => { rs = _rs; rj = _rj; }; | ||
// super(fn); | ||
// walkaround babel which can not extend builtin class | ||
this.then = (new Promise(fn).then); | ||
this._s = "pending"; | ||
this.resolve = (value) => { | ||
if (this.isPending) { | ||
if (isPromiseLike(value)) { | ||
this.task = value; | ||
} | ||
else { | ||
this._s = "fulfilled"; | ||
rs(value); | ||
} | ||
} | ||
}; | ||
this.reject = (reason) => { | ||
if (this.isPending) { | ||
this._s = "rejected"; | ||
rj(reason); | ||
} | ||
}; | ||
this.task = executor; | ||
} | ||
get status() { return this._s; } | ||
@@ -8,3 +34,2 @@ get isPending() { return "pending" === this._s; } | ||
get isRejected() { return "rejected" === this._s; } | ||
_task; | ||
get task() { return this._task; } | ||
@@ -40,33 +65,2 @@ set task(value) { | ||
get isEmpty() { return null == this._task; } | ||
resolve; | ||
reject; | ||
// walkaround babel which can not extend builtin class | ||
then; | ||
constructor(executor) { | ||
let rs; | ||
let rj; | ||
const fn = (_rs, _rj) => { rs = _rs; rj = _rj; }; | ||
// super(fn); | ||
// walkaround babel which can not extend builtin class | ||
this.then = (new Promise(fn).then); | ||
this._s = "pending"; | ||
this.resolve = (value) => { | ||
if (this.isPending) { | ||
if (isPromiseLike(value)) { | ||
this.task = value; | ||
} | ||
else { | ||
this._s = "fulfilled"; | ||
rs(value); | ||
} | ||
} | ||
}; | ||
this.reject = (reason) => { | ||
if (this.isPending) { | ||
this._s = "rejected"; | ||
rj(reason); | ||
} | ||
}; | ||
this.task = executor; | ||
} | ||
} | ||
@@ -73,0 +67,0 @@ |
@@ -1,2 +0,2 @@ | ||
const t=t=>t&&"object"==typeof t&&"function"==typeof t.then;class s{_s=null;get status(){return this._s}get isPending(){return"pending"===this._s}get isFulfilled(){return"fulfilled"===this._s}get isRejected(){return"rejected"===this._s}_task;get task(){return this._task}set task(s){let e;this._task=s,t(s)?e=s:"function"==typeof s&&(e=new Promise(s)),e&&(async()=>{try{const t=await e;s===this._task&&this.resolve(t)}catch(t){s===this._task&&this.reject(t)}})()}get isEmpty(){return null==this._task}resolve;reject;then;constructor(s){let e,i;this.then=new Promise(((t,s)=>{e=t,i=s})).then,this._s="pending",this.resolve=s=>{this.isPending&&(t(s)?this.task=s:(this._s="fulfilled",e(s)))},this.reject=t=>{this.isPending&&(this._s="rejected",i(t))},this.task=s}}export{s as default}; | ||
const t=t=>t&&"object"==typeof t&&"function"==typeof t.then;class s{constructor(s){let e,i;this.then=new Promise(((t,s)=>{e=t,i=s})).then,this._s="pending",this.resolve=s=>{this.isPending&&(t(s)?this.task=s:(this._s="fulfilled",e(s)))},this.reject=t=>{this.isPending&&(this._s="rejected",i(t))},this.task=s}get status(){return this._s}get isPending(){return"pending"===this._s}get isFulfilled(){return"fulfilled"===this._s}get isRejected(){return"rejected"===this._s}get task(){return this._task}set task(s){let e;this._task=s,t(s)?e=s:"function"==typeof s&&(e=new Promise(s)),e&&(async()=>{try{const t=await e;s===this._task&&this.resolve(t)}catch(t){s===this._task&&this.reject(t)}})()}get isEmpty(){return null==this._task}}export{s as default}; | ||
//# sourceMappingURL=index.min.mjs.map |
@@ -9,3 +9,29 @@ (function (global, factory) { | ||
class MutablePromise { | ||
_s = null; // null is bable walkaround? | ||
constructor(executor) { | ||
let rs; | ||
let rj; | ||
const fn = (_rs, _rj) => { rs = _rs; rj = _rj; }; | ||
// super(fn); | ||
// walkaround babel which can not extend builtin class | ||
this.then = (new Promise(fn).then); | ||
this._s = "pending"; | ||
this.resolve = (value) => { | ||
if (this.isPending) { | ||
if (isPromiseLike(value)) { | ||
this.task = value; | ||
} | ||
else { | ||
this._s = "fulfilled"; | ||
rs(value); | ||
} | ||
} | ||
}; | ||
this.reject = (reason) => { | ||
if (this.isPending) { | ||
this._s = "rejected"; | ||
rj(reason); | ||
} | ||
}; | ||
this.task = executor; | ||
} | ||
get status() { return this._s; } | ||
@@ -15,3 +41,2 @@ get isPending() { return "pending" === this._s; } | ||
get isRejected() { return "rejected" === this._s; } | ||
_task; | ||
get task() { return this._task; } | ||
@@ -47,33 +72,2 @@ set task(value) { | ||
get isEmpty() { return null == this._task; } | ||
resolve; | ||
reject; | ||
// walkaround babel which can not extend builtin class | ||
then; | ||
constructor(executor) { | ||
let rs; | ||
let rj; | ||
const fn = (_rs, _rj) => { rs = _rs; rj = _rj; }; | ||
// super(fn); | ||
// walkaround babel which can not extend builtin class | ||
this.then = (new Promise(fn).then); | ||
this._s = "pending"; | ||
this.resolve = (value) => { | ||
if (this.isPending) { | ||
if (isPromiseLike(value)) { | ||
this.task = value; | ||
} | ||
else { | ||
this._s = "fulfilled"; | ||
rs(value); | ||
} | ||
} | ||
}; | ||
this.reject = (reason) => { | ||
if (this.isPending) { | ||
this._s = "rejected"; | ||
rj(reason); | ||
} | ||
}; | ||
this.task = executor; | ||
} | ||
} | ||
@@ -80,0 +74,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MutablePromise=e()}(this,(function(){"use strict";const t=t=>t&&"object"==typeof t&&"function"==typeof t.then;return class{_s=null;get status(){return this._s}get isPending(){return"pending"===this._s}get isFulfilled(){return"fulfilled"===this._s}get isRejected(){return"rejected"===this._s}_task;get task(){return this._task}set task(e){let s;this._task=e,t(e)?s=e:"function"==typeof e&&(s=new Promise(e)),s&&(async()=>{try{const t=await s;e===this._task&&this.resolve(t)}catch(t){e===this._task&&this.reject(t)}})()}get isEmpty(){return null==this._task}resolve;reject;then;constructor(e){let s,i;this.then=new Promise(((t,e)=>{s=t,i=e})).then,this._s="pending",this.resolve=e=>{this.isPending&&(t(e)?this.task=e:(this._s="fulfilled",s(e)))},this.reject=t=>{this.isPending&&(this._s="rejected",i(t))},this.task=e}}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MutablePromise=e()}(this,(function(){"use strict";const t=t=>t&&"object"==typeof t&&"function"==typeof t.then;return class{constructor(e){let s,i;this.then=new Promise(((t,e)=>{s=t,i=e})).then,this._s="pending",this.resolve=e=>{this.isPending&&(t(e)?this.task=e:(this._s="fulfilled",s(e)))},this.reject=t=>{this.isPending&&(this._s="rejected",i(t))},this.task=e}get status(){return this._s}get isPending(){return"pending"===this._s}get isFulfilled(){return"fulfilled"===this._s}get isRejected(){return"rejected"===this._s}get task(){return this._task}set task(e){let s;this._task=e,t(e)?s=e:"function"==typeof e&&(s=new Promise(e)),s&&(async()=>{try{const t=await s;e===this._task&&this.resolve(t)}catch(t){e===this._task&&this.reject(t)}})()}get isEmpty(){return null==this._task}}})); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "mutable-promise", | ||
"version": "1.1.11", | ||
"version": "1.1.12", | ||
"description": "Wrapper for Promise. Resolvable, rejectable, redirectable.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -10,3 +10,3 @@ type ResolveValue<T> = T | PromiseLike<T>; | ||
private _s: string = null; // null is bable walkaround? | ||
private _s: string; | ||
get status(){ return this._s; } | ||
@@ -13,0 +13,0 @@ get isPending(){ return "pending" === this._s; } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27624
311