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

feature: all bind-all when passed an object #48

Closed
kumavis opened this issue Aug 30, 2017 · 1 comment
Closed

feature: all bind-all when passed an object #48

kumavis opened this issue Aug 30, 2017 · 1 comment

Comments

@kumavis
Copy link

kumavis commented Aug 30, 2017

pify has a nice feature where you can promisify an obj's methods

example from readme:

// Promisify all methods in a module
pify(fs).readFile('package.json', 'utf8').then(data => {
	console.log(JSON.parse(data).name);
	//=> 'pify'
});

however this doesnt work when the child methods expect a reference to the owning object

example from my experience:

const Client = require('coinbase').Client
const pify = require('pify')

const client = pify(new Client({}))
const accounts = await client.getAccounts(null) // fails due to unset `this` reference

work around - use bind-all:

const Client = require('coinbase').Client
const pify = require('pify')
const bindAll = require('bind-all')

const client = pify(bindAll(new Client({})))
const accounts = await client.getAccounts(null)
Repository owner deleted a comment from doasync Oct 13, 2017
@sindresorhus
Copy link
Owner

Fixed by #73.

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

2 participants