You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @stefanpenner, thanks for the library, it's great!
Looks like you're aware of subclassing problems, just wanted to share mine. I've run into a problem with subclassing and es6-promise - specifically in then, with const child = new this.constructor(noop); This behaviour seems contrary to native implementations (at least in Chrome and Firefox), which always create a new Promise, regardless of the class of this.
Keeping the child as a Promise lets us reuse/extend Promise.then within our subclass, like so (see working example here):
PromiseSubclass.prototype.then=functionthen(resolve,reject){varreturnVal=Promise.prototype.then.call(this,resolve,reject);// Other actions...returnPromiseSubclass.convert(returnVal);};
However, using this.constructor ends up creating a recursive definition of then that never resolves.
I have built in a work-around in my subclass by detecting if it's an es6-promise (by checking for _state) and cloning into a new Promise before sending to then, so that it accesses the right constructor. So it's all good on my end, just wanted to raise that flag in case it helps!
this is relatively high priority, but will require some aggressive refactoring to do performently.
The text was updated successfully, but these errors were encountered: