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

[question] why using named export for this package? #5

Open
Andarist opened this issue Apr 4, 2018 · 2 comments
Open

[question] why using named export for this package? #5

Andarist opened this issue Apr 4, 2018 · 2 comments

Comments

@Andarist
Copy link
Contributor

Andarist commented Apr 4, 2018

as in the title 😉

@atomrc
Copy link
Owner

atomrc commented Apr 4, 2018

That's, indeed, a very good question.
I believe you are right, a named export is unecessary here (given the module only exports a single function).

As removing the named export would be a breaking change, I am wondering if having both a named and a default export a good idea ... Any opinion on this?
I believe this would work

@Andarist
Copy link
Contributor Author

Andarist commented Apr 4, 2018

It would certainly work - would only add few bytes to CJS file and none for ESM consumers (thanks to tree-shaking in bundlers, ofc ESM will come to node some time in the future, but those extra few bytes shouldnt be much of a concern there).

For CJS consumers it would mean that both of those would be allowed:

var def = require('callbag-debounce').default
var named = require('callbag-debounce').debounce
def === named // true

To support this:

var debounce = require('callbag-debounce')

we'd have to do some hoops like:

module.exports = debounce
module.exports.default = debounce
module.exports.debounce = debounce

Personally I don't think this is particularly good thing.

If you want I can prepare a PR later providing a default export.

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