Private
allPrivate
eventPrivate
isThe name of the event emitter. It will be used in the output logs when errors occur in the event listeners.
Start listening to all events. The provided listener will be invoked each time any event is emitted.
The callback that will be invoked when any event is emitted. It will be invoked with the event name and the event information in its arguments.
Start listening to a specific event. The provided listener will be invoked each time the event is emitted.
The name of the event to listen to.
The callback that will be invoked when the event is emitted. It will be invoked with the event information in its arguments.
Start listening to a specific event only once. The provided listener will be invoked the first time the event is emitted.
If a predicate is provided, the listener will only be invoked if the predicate returns true. The listener will be removed after the first time it is invoked. If the predicate returns false, the event subscription will be kept intact, until the predicate returns true.
The name of the event to listen to.
The callback that will be invoked when the event is emitted. It will be invoked with the event information in its arguments.
Optional
predicate: EventListener<EventMap[K], boolean>An optional predicate that can be used to filter out events. If the predicate returns true, the listener will be invoked.
Create new event emitter based on the existing event emitter with custom logic to define which events are passed through or transformed.
In the configure tap callback function you can create custom logic to pass or transform events to
Example:
type MyEventMap = { 'hello': [name: string], 'one': [], 'unused': [value: number] }
const myEmitter: EventEmitter<MyEventMap> = ...;
type MyPipedEventMap = { 'hello': [name: string], 'two': [] }
const myPipedEmitter = myEmitter.pipe<MyPipedEventMap>(pipe => {
pipe.pass('hello');
pipe.on('one' () => {
pipe.emit('two');
});
});
myPipedEmitter.on('hello', (name: string) => { ... })
myPipedEmitter.on('two', () => { ... })
TODO: Ensure that the pipe has a similar unsubscribe interface as on and once.
Rest
...args: NextEventMap[NextK]Rest
...eventNames: MutualEventKey[]Wait for a specific event. The returned promise will resolve when the event is emitted. The promise will resolve with the event information.
The name of the event to wait for.
Optional
predicate: EventListener<EventMap[K], boolean>Optionally provides a predicate that is invoked with every occurrence of the event. The promise will only resolve once the predicate returns true. It will be invoked with the event information in its arguments. If the predicate throws an error, the promise will be rejected with that error.
An EventGenerator is a type of EventEmitter that exposes the 'emit' method, which allows it to generate events.