* Don't require auth for .ping * Finally introducing loggers * Remove file list caching from disk_space_primitives I don't think this is required anymore with the sync model * Simplification of space primitives and more tests * More reliable online status * Add .zed settings * Remove selfUpdate argument from `writeFile` no longer used - Add `sync` config schema and document sync options - Move sync config handling to client boot logic - Move BootConfig type to ui_types.ts - Remove sync env vars from server - Update documentation for sync and architecture * Improve sync logic and proxy routing for full sync state * Add BoxProxy for late-bound client and improve Lua boot - Add isMobile syscall for editor * Add concurrency to sync process and log indexing duration * Better service worker lifecycle management
34 lines
728 B
TypeScript
34 lines
728 B
TypeScript
export abstract class EventEmitter<HandlerT> {
|
|
private handlers: Partial<HandlerT>[] = [];
|
|
|
|
/**
|
|
* Subscribe to events
|
|
* @param handlers
|
|
*/
|
|
on(handlers: Partial<HandlerT>) {
|
|
this.handlers.push(handlers);
|
|
}
|
|
|
|
/**
|
|
* Unsubscribe from events
|
|
* @param handlers
|
|
*/
|
|
off(handlers: Partial<HandlerT>) {
|
|
this.handlers = this.handlers.filter((h) => h !== handlers);
|
|
}
|
|
|
|
/**
|
|
* Broadcast an event to all subscribers
|
|
* @param eventName
|
|
* @param args
|
|
*/
|
|
async emit(eventName: keyof HandlerT, ...args: any[]): Promise<void> {
|
|
for (const handler of this.handlers) {
|
|
const fn: any = handler[eventName];
|
|
if (fn) {
|
|
await Promise.resolve(fn(...args));
|
|
}
|
|
}
|
|
}
|
|
}
|