Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for use as utility library #11

Open
kjvalencik opened this issue May 5, 2017 · 0 comments
Open

Refactor for use as utility library #11

kjvalencik opened this issue May 5, 2017 · 0 comments

Comments

@kjvalencik
Copy link
Owner

kjvalencik commented May 5, 2017

It's becoming more and more common for libraries not to support providing a promise library. In addition, it's not safe to overwrite or extend the native global Promise.

Instead it may be better to think of these extended promise methods as a utility belt similar to lodash.

You can this today; however, it is verbose and creates an extra Promise allocation.

import P from "extends-promise";

Promise
    .resolve([1, 2, 3])
    .then(res => P.resolve(res).map(x => 2 * x)));

One approach is to make the helper methods high-level and auto-currying. It would be a breaking change because values would go last. E.g.,

import P from "extends-promise";

Promise
    .resolve([1, 2, 3])
    .then(P.map(x => 2 * x));

Long chains are probably good the way they are. But, we may want .thru or .toPromise methods to get a native promise back.

import P from "extends-promise";

P.resolve(Promise.resolve([1, 2, 3]))
    .map(x => 2 * x)
    .thru(x => Promise.resolve(x));

// or

P.resolve(Promise.resolve([1, 2, 3]))
    .map(x => 2 * x)
    .toPromise();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant