/** * HotReloadManager.ts — Sprint 8 * * Manages live module reload with: * - Per-key watcher registration / deregistration * - State migration helper for preserving entity state across reloads * - Version tracking (increments per triggerReload call) * - Isolated watcher error handling (one failure does not block others) * * Design: * - `watch(key, fn)` registers a callback. Multiple watchers per key allowed. * - `triggerReload(key, content, oldState?)` calls each watcher in order. * If a watcher throws, `onError` is called and the next watcher still runs. * - `migrateState(old, newDefaults)` produces a merged state object: * fields present in newDefaults take their value from oldState (preserving * live game values), and any field in newDefaults not in oldState gets its * default value from newDefaults. */ export type ReloadWatcher = (content: TContent, prevState: TState | undefined, meta: { key: string; version: number; }) => void; export interface HotReloadManagerOptions { onError?: (key: string, error: Error) => void; } export declare class HotReloadManager { private watchers; private versions; private readonly onError?; constructor(options?: HotReloadManagerOptions); /** Register a watcher for a module key. Returns an unsubscribe function. */ watch(key: string, fn: ReloadWatcher): () => void; /** Remove a specific watcher. */ unwatch(key: string, fn: ReloadWatcher): void; /** Remove ALL watchers for a key. */ unwatchAll(key: string): void; /** Whether at least one watcher is registered for the key. */ isWatched(key: string): boolean; /** * Trigger a reload for the given key. * * @param key Module identifier (file path, scene name, etc.) * @param content New module content (AST, raw code, etc.) * @param oldState Previous runtime state to pass to watchers for migration */ triggerReload(key: string, content: TContent, oldState?: TState): void; /** * Produce a merged state after a reload. * * Strategy: * - Start with `newState` (the defaults from the new module). * - For each key in `newState`, if `oldState` also has that key, prefer * the old value (preserves live runtime values like hp, position, etc.). * - Keys in `oldState` NOT present in `newState` are discarded (the new * module removed that field). * * If `oldState` is null/undefined, returns `newState` unchanged. */ migrateState>(oldState: T | null | undefined, newState: T): T; /** How many times triggerReload has been called for this key. */ version(key: string): number; } //# sourceMappingURL=HotReloadManager.d.ts.map