API Reference
Rockets Core API
nestjs-event
classes
EventListenerOn

Class: abstract EventListenerOn<E>

Abstract event listen on class.

To create a custom event listener, extend the EventListenerOn class and implement the [listen]EventListenerOn#listen method. The [listen]EventListenerOn#listen method will receive the payload dispatched by EventDispatchService.

Example

// event payload type
type MyPayloadType = {id: number, active: boolean};
 
// example event class
class MyEvent extends EventSync<MyPayloadType> {}
 
// example listener class
class MyListenOn extends EventListenerOn<MyEvent> {
  // custom handler
  listen(event: MyEvent): void {
    console.log(event.payload);
  }
}
 
// new listener
const myListener = new MyListenOn();
 
// subscribe to the event
EventListenService.on(MyEvent, myListener);
 
// and you can remove the listener easily
listener.remove();

Extends

Type Parameters

Type Parameter
E

Implements

Constructors

new EventListenerOn()

new EventListenerOn<E>(_options): EventListenerOn<E>

Constructor

Parameters

ParameterTypeDescription
_optionsEventListenOnOptionsInterfaceListener options

Returns

EventListenerOn<E>

Overrides

EventListener.constructor

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener-on.ts:47 (opens in a new tab)

Accessors

options

get options(): EventListenOnOptionsInterface

Default listener options.

Returns

EventListenOnOptionsInterface

The default listener options.

Implementation of

EventListenOnInterface.options

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener-on.ts:56 (opens in a new tab)

Methods

listen()

abstract listen(event): EventReturnType<E>

Listen to an event.

Parameters

ParameterType
eventEventInstance<E>

Returns

EventReturnType<E>

Implementation of

EventListenOnInterface.listen

Inherited from

EventListener.listen

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener.ts:60 (opens in a new tab)


remove()

remove(): void

Remove the subscription.

Returns

void

Implementation of

EventListenOnInterface.remove

Inherited from

EventListener.remove

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener.ts:85 (opens in a new tab)


subscription()

subscription(emitterListener): void

Internal

Called after successful subscription.

Parameters

ParameterTypeDescription
emitterListenerListenerThe Listener object returned by EventEmitter2

Returns

void

Implementation of

EventListenOnInterface.subscription

Inherited from

EventListener.subscription

Defined in

.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener.ts:68 (opens in a new tab)