JS API Reference EventSubject class

EventSubject class

The EventSubject class is used to enable the concept of listening and emitting evens while maintaining type safety for the subscribing listeners. The type Generic T hereby refers to the event parameter passed on the listeners when emitting events.

Signature

export declare class EventSubject<T> 

Constructor

Constructs a new instance of the EventSubject class

Parameters

None.

Properties

protected _oneTimeSubscriptions

Type: IEventListener<T>[]

protected _subscriptions

Type: IEventListener<T>[]

listenerCount

Type: number

Methods

emit

Emits an event on subject.

Parameters

ParameterTypeDescription
eventTThe event to emit

Returns:

void

once

Add a listener callback that gets only called once and then removed from the subject.

Parameters

ParameterTypeDescription
listenerIEventListener<T>The listener callback to subscribe

Returns:

IEventSubscription

removeAllSubscriptions

Remove all listeners that are currently subscribed to the event

Parameters

None.

Returns:

void

subscribe

Subscribe a listener callback for all upcoming events on the subject

Parameters

ParameterTypeDescription
listenerIEventListener<T>The listener callback to subscribe

Returns:

IEventSubscription

a subscription that can later be used to unsubscribe the listener, see IEventSubscription

unsubscribe

Unsubscribe a previously added listener callback from the event

Parameters

ParameterTypeDescription
listenerIEventListener<T>The listener callback to unsubscribe

Returns:

void