@jirkasa/code-box
Version:
Showcase code samples on the web with a container that lets users select and display different samples.
34 lines (33 loc) • 945 B
TypeScript
/**
* Represents event source that can be used to fire and subscribe to events.
* @template T Event sender.
* @template U Event value.
*/
declare class EventSourcePoint<T, U> {
/** Stores registered handlers. */
private handlers;
/** Used for assigning ids to handlers. */
private count;
/**
* Creates new event source point.
*/
constructor();
/**
* Registeres new handler.
* @param handler Function to be called when event is fired.
* @returns Id of registered handler.
*/
subscribe(handler: (sender: T, value: U) => void): number;
/**
* Unsubscribes event handler.
* @param handlerId Id of handler that should be unsubscribed.
*/
unsubscribe(handlerId: number): void;
/**
* Fires new event.
* @param sender Sender of event.
* @param value Value of event.
*/
fire(sender: T, value: U): void;
}
export default EventSourcePoint;