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
Parameter | Type | Description |
---|---|---|
_options | EventListenOnOptionsInterface | Listener options |
Returns
Overrides
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
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
Parameter | Type |
---|---|
event | EventInstance <E > |
Returns
EventReturnType
<E
>
Implementation of
Inherited from
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
Inherited from
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
Parameter | Type | Description |
---|---|---|
emitterListener | Listener | The Listener object returned by EventEmitter2 |
Returns
void
Implementation of
EventListenOnInterface
.subscription
Inherited from
Defined in
.tmp/repos/rockets/packages/nestjs-event/src/listeners/event-listener.ts:68 (opens in a new tab)