eventin
Type-restrained event emitter.
Install & Usage
npm install eventin
import Eventin from 'eventin';
enum EventType {
OPEN = 'open',
CLOSE = 'close',
TOGGLE = 'toggle',
}
const e = new Eventin<
EventType,
{
[EventType.OPEN]: { id: string };
[EventType.CLOSE]: { source: number };
[EventType.TOGGLE]: boolean;
}
>();
const unlisten = e.listen(EventType.OPEN, ({ id }) => console.log(id));
const unlisten = e.listen(EventType.OPEN, ({ source }) => console.log(source));
e.emit(EventType.OPEN, { id: 'eventin' });
e.emit(EventType.OPEN, 123);
const unlisten = e.listen(EventType.OPEN, ({ id }) => console.log(id), {
once: true,
});
e.emit(EventType.OPEN, { id: 'eventin' }, { sync: true });
e.unlistenAll(EventType.OPEN);
e.unlistenAll();
License
MIT