tlojs
Version:
The Last One - The last npm package you'll need to install
50 lines (49 loc) • 1.36 kB
TypeScript
import { Type } from "../types/type";
declare type EventCallback = (e: BaseEvent) => void;
export declare class EventHub {
private registered;
/**
* Dispatches a an event to any listeners. If no listeners exist, the event will be ignored
* @param event EventBase
*/
dispatch(event: BaseEvent): void;
/**
* Register a callback to an event type
* @param eventType
* @param callback
* @returns
*/
register(eventType: Type<BaseEvent>, callback: EventCallback): EventRegistration;
/**
* Unregister a callback from an event type
* @param eventType
* @param callback
* @returns
*/
unregister(eventType: Type<BaseEvent>, callback: EventCallback): void;
}
/**
* The global event hub
*/
export declare const GlobalEventHub: EventHub;
export declare abstract class BaseEvent {
data?: any;
globalHub: EventHub;
abstract name: string;
constructor(data?: any);
/**
* Any inherited class can easily dispatch to the global event hub
*/
dispatch(): void;
}
declare class EventRegistration {
private eventType;
private callback;
private eventHub;
constructor(eventType: Type<BaseEvent>, callback: EventCallback, eventHub: EventHub);
/**
* Easy shortcut to unregister an event
*/
unsubscribe(): void;
}
export {};