atomrc / callbag-debounce

Debounce ⏱ operator for Callbag 👜
MIT License
12 stars 5 forks source link

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

Open Andarist opened 6 years ago

Andarist commented 6 years ago

as in the title 😉

atomrc commented 6 years ago

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 commented 6 years ago

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.