dmonad / lib0

Monorepo of isomorphic utility functions
MIT License
345 stars 63 forks source link

default array value for emit() args #44

Closed broofa closed 1 year ago

broofa commented 1 year ago

Fixes bug where calling myObservable.emit('some-event') (with no 2nd argument) throws a "TypeError: args is not iterable (cannot read property undefined)" error.

dmonad commented 1 year ago

Hi @broofa,

this was quite intentional. In this project, I don't use polymorphism (if an argument can either be undefined or type X, then it is polymorphism). There are a few exceptions, but this is not likely to become one of them.

broofa commented 1 year ago

I don't use polymorphism

Any particular reason for that?

I ask because the signature for emit() here is noticeably different from the defacto standard set by node. It creates a rather unpleasant trap for unsuspecting developers.

dmonad commented 1 year ago

JavaScript engines deoptimize polymorphic functions. I linked some articles in the README.

Obviously, this doesn't matter for .emit. But I do regularly log deoptimized functions to find performance bottlenecks. Making more functions polymorphic (just for convenience) will make it harder for me to debug.