yeoman / insight

Node.js module to help you understand how your tool is being used by anonymously reporting usage metrics to Google Analytics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the point of first argument in askPermission callback?

markelog opened this issue · comments

It seems always called with null as first argument. Is it because that first arg is usually is error?

Also would it make sense to make it return a promise?

With promise, it seems it would look nicer -

// Instead of
insight.askPermission('', function(error, result) {});
// It could be
insight.askPermission(/*optional argument now*/).then(..., ...);

It pass an error as first parameter to be compliant with Node callback interface.

If you want to send a PR to return a promise, feel free to do so. But we need to keep the callback function to maintains backward compatibility.

Is it because that first arg is usually is error?

Yes. It's following Node.js convention.

Also would it make sense to make it return a promise?

Yes. This module was made before Promises was a thing.

But we need to keep the callback function to maintains backward compatibility.

The same proposition, i believe, was raised in node repo, but was deemed to be confusing.

I tend to agree, as contr proposal, it could be done through one interface but with increased major.

If you want to send a PR to return a promise, feel free to do so

Yeah, that was my intention, if it feels acceptable to you. But i would like to go further with it, by rewriting the whole thing on es6 and replace mocha with ava. Would be nice exercise for me.

But i would like to go further with it, by rewriting the whole thing on es6 and replace mocha with ava

Yeoman still actively support pre 4.0 Node versions. We're not ready to go full es6 in our modules just yet.

I would just do a promise-only API in a major bump. Can use https://github.com/floatdrop/pinkie-promise for Node.js 0.10 support. This module is stable anyways. People not wanting a promise interface can just stay on the current version. I agree with @SBoudrias on the ES6 change though. Still a bit early. Maybe in half a year.

I would just do a promise-only API in a major bump

I'm good with going that path too.

Yeoman still actively support pre 4.0 Node versions. We're not ready to go full es6 in our modules just yet.

I meant with using transpiler of course, yeoman would need to change their use of askPermission, everything else should stay the same.

@markelog I don't think it's worth the trouble introducing a compile-step for such a small module. Especially not now that we soon can use most of ES2015 natively.

I don't think it's worth the trouble introducing a compile-step for such a small module.

Really? Hm, seems as common practise, especially for small modules, harder is the opposite - rewrite big modules, i would even start to use flow here.

Especially not now that we soon can use most of ES2015 natively.

That would mean dropping support for other versions of node, without the transpiler you have to drop support for all < 6 nodes. In world where .10 is most popular environment, don't know when the time will come when you can do that without pain.

In other words, you sure?

Yes totally sure. We don't need es6 in this module.

Suite yourself, at this junction it wouldn't be interesting to me

Let's keep this open. Even if you don't want to help out, we still want to add promise support.

That issue was about first argument of askPermission, promise was a side question just like es6, i don't think it would be useful for potential contributor to read this thread.

seems as common practise

"Common" doesn't necessarily mean good.

"Uncommon" does though, not always, but in lot of cases