EventEmitter2 (with types!)
Existing EventEmitter libraries typically do not provide much support for indicating what events and payloads are available on a given emitter. This library adds that support to the popular EventEmitter2 library.
Usage
Events can be described as a string (when just the event name is needed because there is no expected payload) or as an object with a payload:
import {createEmitter} from '@bscotch/emitter';
type MySimpleEvent = "my-simple-event";
interface MyComplexEvent {
name: "my-complex-event";
payload: [arg0: string, arg1: { foo: number }];
}
type MyEvents = [MySimpleEvent, MyComplexEvent];
const emitter = createEmitter<MyEvents>();
emitter.on('my-simple-event', () => {});
emitter.emit('my-simple-event');
emitter.on('my-complex-event', (arg0, arg1) => {});
emitter.emit('my-complex-event', 'foo', { foo: 1 });