This seems like a really elegant way to avoid thenable assimilation for
time immemorial.

Presumably certain promise libraries would try reset the global Promise to
AssimilatingPromise (or whatever) for full parity with polyfilled
environments, which would be fine. If you expect native promises, or you're
not using promises at all, you can completely avoid any namespace pollution.

Another nice feature is that it's a simple opt-in rather than a much more
complex opt-out approach that something like anti-branding would require.


On Fri, Dec 20, 2013 at 10:38 AM, Kevin Smith <[email protected]> wrote:

> I highly doubt that will be possible -- experience strongly suggests that
>> every odd feature _will_ be relied on in the wild by that time. If we think
>> thenable assimilation is a problem then we have to remove it now. I, for
>> one, would welcome that. We could still provide an _explicit_ thenable
>> adaptor method in the Promise API.
>
>
> Agreed 100%.  I'm skeptical that we've really done our homework analyzing
> the backward compatibility constraints for this design.
>
> Now that we have a proper cross-realm nominal Promise type (which we
> didn't have before), the right thing to do is to use nominal typing.  We
> should have started from that point and then figured out how current
> thenables can cope.
>
> Too late?
>
> Probably, but just for kicks, here's another solution:
>
> Provide a Promise subclass, BorgPromise (Star Trek reference) which does
> simple thenable coercion in its then function (no funky WeakMap).  All
> libraries which might interact with thenables switch to using BorgPromises.
>  At some point in the future usage of non-Promise thenables will approach
> insignificance, at which time BorgPromise libraries can freely switch to
> using regular Promises, and assimilation can fade into history.
>
> BorgPromise doesn't even have to be specified by TC39.  It can be a user
> library:
>
>     // Remove this line sometime in the future...
>     import Promise from "package:borg-promise";
>
>     // package:borg-promise
>     class BorgPromise extends Promise {
>
>         then(onResolve, onReject) {
>
>             if (typeof onResolve !== "function") onResolve = x => x;
>
>             return super.then(x => {
>
>                 // NOTE: x is a non-promise
>                 return isThenable(x) ?
>                     x.then(onResolve, onReject) :
>                     onResolve(x);
>
>             }, onReject);
>         }
>     }
>
>     export { BorgPromise as default };
>
>
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to