ecspresso
Version:
A minimal Entity-Component-System library for typescript and javascript.
19 lines (18 loc) • 631 B
TypeScript
export default class EventBus<EventTypes> {
private handlers;
/**
* Subscribe to an event
*/
subscribe<E extends keyof EventTypes>(eventType: E, callback: (data: EventTypes[E]) => void): () => void;
/**
* Subscribe to an event once
*/
once<E extends keyof EventTypes>(eventType: E, callback: (data: EventTypes[E]) => void): () => void;
/**
* Internal method to add an event handler
*/
private addHandler;
publish<E extends keyof EventTypes>(eventType: E, data?: EventTypes[E]): void;
clear(): void;
clearEvent<E extends keyof EventTypes>(eventType: E): void;
}