#What EventEmitter for cross platform libs?

26 messages · Page 1 of 1 (latest)

maiden idol
#

hey, i want to create class that is also event emitter and i don't want to use node specific event emitter as i am targeting Web as well

  • Why not EventTarger as its supported on almost every runtime?
    • Its not TypeScript rich, i can't defined the event names
    • Forced to dispatch with Event instance only, not suitable for error events
  • Why not custom event emitter?
    • Custom event emitter doesn't always follow the same standards as build-in emitter's
    • Bug-possible
    • Bad user experience as it slows down the development process
  • Why not nodeJS event Emitter
    • I want to target as much platforms as possible
    • Bad design, legacy emitter design
    • I don't like NodeJS emitters
rain portal
#

sooo you don't want built-in events, and you don't want custom events?

#

Custom event emitter doesn't always follow the same standards as build-in emitter's

Bad design, legacy emitter design
these just seem conflicting

somber herald
#

I make an effort to write source code that can be run by node, deno, or bun.

I'm curious what do you mean exactly by "EventEmitter"?

maiden idol
#

baskicly no suggestions on what event names are available

#

thats the main problem

rain portal
#

so im confused what solution you see here

maiden idol
#

nah, i don't see solution thats why i am asking here damn

rain portal
#

you have too many restrictions that conflict

maiden idol
#

maybe someone already faced same problem if you know what i mean

rain portal
#

it's impossible to have something that's simultaneously not custom and not built-in

#

or something that's simultaneously standardized and not legacy (because legacy is basically the same as standard)

maiden idol
#

like i said i just want to know if anyone faced same problem and what way they went

rain portal
#

the problem of disliking every possible solution?

#

just use the eventemitter
you can copy it to get web support, and modify it to get strict types
it's a known api

maiden idol
maiden idol
grim cedar
#

A very simple event emitter is pretty trivial to write too... https://github.com/TypeStrong/typedoc/blob/master/src/lib/utils/events.ts is what I use, have copied it (or a version with slight variations, some projects don't need priority, but need once listeners, or some other feature) for years at this point. I've made exactly one code change to the emitter since introducing it, to fix a new eslint rule.

deep oasis
maiden idol
#

I am about to use EventTarget anyway, but i am leaving this post open, so maybe someone has game changing idea or something, just want to say i am not beginner so basic answer is propably already considered, i was thinking i could create ECMA proposal for event emitter pattern bc we definitely need one, Web APIs EventTarget is designed to work well with DOM, but for us its noit the case

maiden idol
#

or maybe let me close it