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

Support context #6

Closed
dsblv opened this issue Sep 8, 2015 · 7 comments
Closed

Support context #6

dsblv opened this issue Sep 8, 2015 · 7 comments

Comments

@dsblv
Copy link
Contributor

dsblv commented Sep 8, 2015

As far as I can get, right now the only way to carry the context through pify is to explicitly .bind() it:

var promise = pify(obj.method.bind(obj))(args);

This is all cool and native, but wouldn't it be more clean to make context an option:

var promise = pify(obj.method, {context: obj})(args);

Especially when one wants to save opts somewhere and pify several methods of one object?

This is more of a question than request, although I could make a PR if it souds like a good idea 😏

@dsblv
Copy link
Contributor Author

dsblv commented Sep 8, 2015

pify.all() is super useful untill you have to deal with external module with some unpifiable methods.

@sindresorhus
Copy link
Owner

I don't see the point when you can use .bind(). Binding is the correct way to do it and it's more explicit.

but wouldn't it be more clean

I find .bind more clean.

@sindresorhus
Copy link
Owner

pify.all() is super useful untill you have to deal with external module with some unpifiable methods.

Can you elaborate? Might be something that can be done about that ;)

@dsblv
Copy link
Contributor Author

dsblv commented Sep 8, 2015

The problem is that we can't say if the function will ever call the callback that pify attaches to arguments, right?

So the only way I see is to filter methods manually. Question is: what is the better way to do this (for consumers)?

var pifiedObj = pify.all(obj, {
  include: ['some', 'good', 'methods'],
  exclude: ['bad', 'ones']
});

What do you think?

@sindresorhus
Copy link
Owner

I've looked at the Bluebird promisify code and it tries to infer using magic, but I'd rather it be explicit.

Your suggestion looks good. Wanna do a PR? Include and exclude should be mutually exclusive.

@dsblv
Copy link
Contributor Author

dsblv commented Sep 8, 2015

Yes, I'm in, thanks!

@jdalton
Copy link

jdalton commented Dec 22, 2016

Related to #27?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants