The 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.
Emits an event on the pipe to be received by the new EventEmitter.
The name of the event to emit.
Rest
...args: NextEventMap[NextK]The arguments of the event to emit.
Start listening to a specific event on the source event emitter.
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.
Ensures that events (with the provided event names) are passed through as-is to the next event emitter. Note: Only event names that exist on both sides of the pipe and that have the same argument array signature are allowed to be passed.
Rest
...eventNames: MutualEventKey[]The names of the events you want to pass through as-is to the next event emitter. Only events that exist on both sides of the pipe and that have the same argument array signature are allowed to be passed.
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
EventEmitter
can be used to listen to structured events based on a providedEventMap
. The event map describes the possible events. Each event is described as a record where the key is a string representing the event name and the value is a typed array representing the arguments that that event is emitted with.An
EventEmitter
can be used to listen to events directly usingon
and in case of more complex behaviour it can be used to derive newEventEmitters
usingpipe
.Example: