scottcorgan / tiny-emitter

A tiny (less than 1k) event emitter library
MIT License
935 stars 67 forks source link

Callback logic #48

Open jssuttles opened 9 months ago

jssuttles commented 9 months ago

https://github.com/scottcorgan/tiny-emitter/blob/4e6b2eb5869fb4ba862accaef7d16a7051349f4f/index.js#L58C6-L58C16

Doesn't this ternary statement mean that if the callback isn't found in the list of associated callbacks, then it'll remove all associated callbacks?

scottcorgan commented 6 months ago

What I remember this being for is to delete only the referenced callback, and reassign the remaining event callbacks to the current event listening object.

It's a bunch of awkward code to avoid memory leaks and unnecessary allocations.

This was a long time ago, so apologies if I'm not remembering correctly.