Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031import type { Unsubscribe } from "./shell/workbench.ts";
/** * The file access the stock views need. It stands in for the kernel's filesystem and the Loro docs * behind it (D16); views keep no state of their own beyond what is on screen (D11). */export interface Files { list(): string[]; read(path: string): string | undefined; write(path: string, text: string): void; /** Calls `listener` with the path of every write. */ watch(listener: (path: string) => void): Unsubscribe;}
export function memoryFiles(initial: Record<string, string>): Files { const files = new Map(Object.entries(initial)); const listeners = new Set<(path: string) => void>(); return { list: () => [...files.keys()].sort(), read: (path) => files.get(path), write(path, text) { files.set(path, text); for (const listener of listeners) listener(path); }, watch(listener) { listeners.add(listener); return () => listeners.delete(listener); }, };}