@3xpo/events
v1.0.18
Published
NodeJS EventEmitter Polyfill in TS, with event type support
Downloads
84
Readme
@3xpo/events
Installation
pnpm i @3xpo/events
Usage
import EventEmitter from '@3xpo/events';
const emitter = new EventEmitter<{
event1: (arg1: string, arg2: number) => void;
event2: (arg1: string) => void;
}>();
emitter.on('event1', (arg1, arg2) => {
console.log(arg1, arg2);
});
emitter.emit('event1', 'hello', 123);
Note
The EventEmitter is typesafe. If you want a non-typesafe eventemitter, either pass <any>
or use NodeEventEmitter.
Note that typesafety is not available in pure JS.