kevinbeaty / any-promise

NOTE: You probably want native promises now
MIT License
179 stars 17 forks source link

Shortcut registrations #14

Closed jamestalmage closed 8 years ago

jamestalmage commented 8 years ago

It would be great to create a register folder in the package that contained a number of shortcut registrations.

This solves the problem of import hoisting with ES6 modules:

import Promise from 'bluebird';
import register from 'any-promise/register';
register('bluebird', {Promise: Promise});
import 'uses-any-promise'; // this is hoisted, so it actually occurs before the registration

With a shortcut you can do:

import 'any-promise/register/bluebird';

Recent versions of Node and many test runners offer a --require flag. This can be useful for that too:

$ ava --require any-promise/register/bluebird

We are doing it for any-observable (a fork of this that does the same thing for Observables): https://github.com/sindresorhus/any-observable/pull/10

kevinbeaty commented 8 years ago

Great idea.

shamelessly steal entire implementation from any-promise

haha. Nice.

kevinbeaty commented 8 years ago

Another nice thing about this approach is it will work in the browser without requiring "Advanced Registration" for identifying the constructor. I am going to update the README to make this the preferred registration method.

/cc @tnguyen14 You will probably find the new "Registration Shortcut" feature of any-promise useful.

jamestalmage commented 8 years ago

Another nice thing about this approach is it will work in the browser without requiring

Yes, I realized that when writing our browser tests for any-observable.

tnguyen14 commented 8 years ago

Thanks for the tip @kevinbeaty!

kevinbeaty commented 8 years ago

Published in v 1.3.0