dmonad / lib0

Monorepo of isomorphic utility functions
MIT License
368 stars 65 forks source link

default array value for emit() args #44

Closed broofa closed 2 years ago

broofa commented 2 years 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 2 years 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 2 years 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 2 years 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.