// oxlint-disable require-yield import type { Api, Operation, Result } from "effection"; import { createApi } from "effection/experimental"; import type { Node } from "./types.ts"; import { TreeContext } from "./state.ts"; export interface Dispatch { dispatch(event: unknown): Operation>; getNodeById(id: string): Operation; } export const DispatchApi: Api = createApi( "freedom:dispatch", { *dispatch(_event: unknown): Operation> { return { ok: false, error: new Error("unhandled") }; }, *getNodeById(id: string): Operation { const tree = yield* TreeContext.expect(); return tree.nodes.get(id); }, }, );