Skip to content

Pass multiple args to listener

Compare
Choose a tag to compare
@apollo79 apollo79 released this 21 Apr 12:10

This version has the number 2.0.0, because it works different like the other versions before. It has its own branch and there will be improvements on 1.x.x and 2.x.x in the future. Chose the technology that you like the most.

You can now use on like the following:

target.on("message", (sender, message) => {
  // ...
})

and emit:

target.emit("message", "kevin", "Hi Detlef");

The type of EventMap is the following:

const target = new EventEmitter<{
  message: [string, string];
}>();

!!! WARNING !!!:
removeEventListener can't anymore be used with listeners added with on, once and subscribe and off is no more compatible with listeners added with addEventListener!
emit / publish / dispatch does not call listeners added with addEventListener, the same at dispatchEvent and on, once, subscribe!

EventEmitter only extends EventTarget, meaning you can use either EventTarget methods or EventEmitter methods or both, but separated!

Full Changelog: 1.3.1.1...2.0.0