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
Parameter | Type | Description |
---|---|---|
event | T | The event to emit |
Returns:
void
once
Add a listener callback that gets only called once and then removed from the subject.
Parameters
Parameter | Type | Description |
---|---|---|
listener | IEventListener<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
Parameter | Type | Description |
---|---|---|
listener | IEventListener<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
Parameter | Type | Description |
---|---|---|
listener | IEventListener<T> | The listener callback to unsubscribe |
Returns:
void