API Reference
Rockets Core API
nestjs-event
classes
EventListenService

Class: EventListenService

Event Listen Service

This service coordinates the registering of listeners on dispatched events to the NestJS EventEmitter module.

Constructors

new EventListenService()

new EventListenService(eventEmitter): EventListenService

Constructor

Parameters

ParameterTypeDescription
eventEmitterEventEmitter2Injected event emitter instance

Returns

EventListenService

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/services/event-listen.service.ts:26 (opens in a new tab)

Methods

createListenWrapper()

protected createListenWrapper<E>(listener): (e) => EventReturnType<E>

Internal

Type Parameters

Type Parameter
E

Parameters

ParameterType
listenerEventListenOnInterface<E>

Returns

Function

Parameters
ParameterType
eEventInstance<E>
Returns

EventReturnType<E>

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/services/event-listen.service.ts:107 (opens in a new tab)


on()

on<E>(eventClass, listener, options): void

Adds a listener to the end of the listeners list for the specified event.

See the EventEmitter2.on (opens in a new tab) documentation for more details about the underlying emitter API.

Type Parameters

Type Parameter
E

Parameters

ParameterTypeDescription
eventClassEventClassInterface<E>The event class to subscribe to. This is the class, NOT an instance.
listenerEventListenOnInterface<E>Instance of the event listener class to attach to the event.
optionsEventListenOnOptionsInterfaceOverriding options.

Returns

void

Example

import { Injectable, OnModuleInit } from '@nestjs/common';
import { EventListenService, EventListenerOn } from '@concepta/nestjs-events';
import { TargetEvent } from 'target-module';
 
class MyListener extends EventListenerOn<TargetEvent> {
  listen(event: TargetEvent) {
    console.log(event.payload);
  }
}
 
@Injectable()
class MyClass implements OnModuleInit {
constructor(private eventListenService: EventListenService) {}
 
onModuleInit() {
// listener instance
const listener = new MyListener();
// register the listener
this.eventListenService.on(TargetEvent, listener);
}
}

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/services/event-listen.service.ts:66 (opens in a new tab)