ts-hashlife
Version:
Efficient TypeScript implementation of HashLife, an optimized algorithm for simulating Conway's Game of Life with memoization and quadtree-based compression.
39 lines (38 loc) • 1.12 kB
TypeScript
import { Pattern } from "./formats";
type EventCallback<T = unknown> = (data: T) => void;
export interface EventMap {
fps: string | number;
population: string | number;
generation: string | number;
zoom: string | number;
step: string | number;
"mouse:x": string | number;
"mouse:y": string | number;
"pan:x": string | number;
"pan:y": string | number;
"pattern:load": Pattern;
"start": boolean;
"stop": boolean;
}
declare class EventBus {
#private;
/**
* Emit an event with data
*/
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void;
/**
* Subscribe to an event
* @returns A function to unsubscribe
*/
on<K extends keyof EventMap>(event: K, callback: EventCallback<EventMap[K]>): () => void;
/**
* Unsubscribe from an event
*/
off<K extends keyof EventMap>(event: K, callback: EventCallback<EventMap[K]>): void;
/**
* Clear all listeners for an event or all events
*/
clear<K extends keyof EventMap>(event?: K): void;
}
declare const eventBus: EventBus;
export default eventBus;