Class: TypedEventEmitter<T>
A strongly-typed Tiny Event Emitter.
Type Parameters
Type Parameter | Default type |
---|---|
T extends EventMap <T > | DefaultEventMap |
Constructors
Constructor
ts
new TypedEventEmitter<T>(): TypedEventEmitter<T>;
Creates a new TypedEventEmitter instance.
Returns
TypedEventEmitter
<T
>
Properties
Property | Modifier | Type | Description |
---|---|---|---|
e | public | EventListenerMap | The internal event listener map for the emitter. |
Methods
emit()
ts
emit<K>(event: Key<K, T>, ...args: Args<K, T>): this;
Emit an event.
Type Parameters
Type Parameter |
---|
K |
Parameters
Parameter | Type | Description |
---|---|---|
event | Key <K , T > | The event name. |
...args | Args <K , T > | The arguments to pass to the listeners. |
Returns
this
the current instance for chaining
off()
ts
off<K>(event: Key<K, T>, listener?: Listener<K, T>): this;
Unsubscribe from an event.
Type Parameters
Type Parameter |
---|
K |
Parameters
Parameter | Type | Description |
---|---|---|
event | Key <K , T > | The event name. |
listener ? | Listener <K , T > | Optional. The listener function to remove. |
Returns
this
the current instance for chaining
Remarks
When no listener is provided, all listeners for the event will be removed, otherwise only the specified listener will be removed.
on()
ts
on<K>(
event: Key<K, T>,
listener: Listener<K, T>,
ctx?: any): this;
Subscribe to an event with a typed listener.
Type Parameters
Type Parameter |
---|
K |
Parameters
Parameter | Type | Description |
---|---|---|
event | Key <K , T > | The event name. |
listener | Listener <K , T > | The listener function. |
ctx ? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining
once()
ts
once<K>(
event: Key<K, T>,
listener: Listener<K, T>,
ctx?: any): this;
Subscribe to an event once with a typed listener.
Type Parameters
Type Parameter |
---|
K |
Parameters
Parameter | Type | Description |
---|---|---|
event | Key <K , T > | The event name. |
listener | Listener <K , T > | The listener function. |
ctx ? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining