import type { JourneyStep } from './stepTable'; /** * ONE SUBSCRIPTION, ONE TEARDOWN, ONE PLACE THAT DECIDES A STEP IS DONE. * * The journey used to attach a fresh listener inside each per-screen promise * and resolve it from inside that closure, which is why "which event means * done" was invisible (see `stepTable.ts`) and why teardown could not reach the * listeners, timers and half-started mounts those closures owned. * * Here instead: * * - every listener the journey attaches is attached by `attach()`, using the * events `stepTable.ts` declares, and its detach is registered in the one * release list; * - a step is a state with at most one waiter, and it leaves that state only * through `complete()` / `fail()` — both of which live here, not in a closure; * - `teardown()` runs every release and rejects whatever is still waiting, and * afterwards `run()` refuses outright. Nothing can build, mount or complete * into a container the host has already reclaimed: the mount-after-destroy * race is not representable rather than being guarded case by case. * * The machine is deliberately not an event bus: each screen instance is still * its own emitter (the form module creates one per screen), so "one * subscription" means one owner of every subscription, not one `on()` call. */ /** anything the journey listens to: a form screen instance, or the idv flow */ export type StepEmitter = { on(event: string, listener: (...args: never[]) => void): unknown; off?(event: string, listener: (...args: never[]) => void): unknown; }; /** wire a step's emitter; defaults to the events its row declares */ export type StepAttach = (emitter: StepEmitter, events?: readonly string[]) => void; /** * Builds and starts a step. Runs inside the teardown guard, so a destroyed * journey never even constructs a screen. Anything promise-like it returns is * awaited: a rejection fails the step, a resolution on its own does not * complete it (the declared signal does). */ export type StepOpener = (attach: StepAttach) => unknown; export type StepMachine = { isTorn: () => boolean; isPending: (step: JourneyStep) => boolean; complete: (step: JourneyStep, value?: unknown) => void; fail: (step: JourneyStep, error: Error) => void; /** register a detach / unmount / clearTimeout for the single teardown */ release: (release: () => void) => void; run: (step: JourneyStep, open: StepOpener) => Promise; teardown: () => void; }; export declare const TORN_DOWN = "The journey was destroyed before this step completed."; export declare const mkStepMachine: () => StepMachine; //# sourceMappingURL=stepMachine.d.ts.map