Packages > @fluidframework/tree > ISubscribable
ISubscribable Interface
An object which allows the registration of listeners so that subscribers can be notified when an event happens.
EventEmitter
can be used as a base class to implement this via extension.
Signature
export interface ISubscribable<E extends Events<E>>
Type Parameters
Parameter | Constraint | Description |
---|---|---|
E | Events<E> |
Example
type MyEventEmitter = IEventEmitter<{
load: (user: string, data: IUserData) => void;
error: (errorCode: number) => void;
}>
Methods
Method | Return Type | Description |
---|---|---|
on(eventName, listener) | () => void | Register an event listener. |
Method Details
on
Register an event listener.
Signature
on<K extends keyof Events<E>>(eventName: K, listener: E[K]): () => void;
Type Parameters
Parameter | Constraint | Description |
---|---|---|
K | keyof Events<E> |
Parameters
Parameter | Type | Description |
---|---|---|
eventName | K | the name of the event |
listener | E[K] | the handler to run when the event is fired by the emitter |
Returns
a function which will deregister the listener when run. This function has undefined behavior if called more than once.
Return type: () => void