Skip to content

Interface: ModeEngine<Ctx>

Defined in: modal/engine.ts:262

Type Parameters

Ctx

Ctx

Properties

spec

readonly spec: ModeEngineSpec<Ctx>

Defined in: modal/engine.ts:294

The spec (frozen) — projections read it.

Methods

canDispatch()

canDispatch(command, payload?): boolean

Defined in: modal/engine.ts:282

Would dispatching this command do anything right now? Derived by dry-running the pure reducer against the committed state (a returned patch that changes nothing → false); spec.available overrides for verbs and gated commands; escape/blur resolve their own steps. The bar projection disables caps from this — gating is mechanical, not hand-written per surface. Unknown command → throws, like dispatch.

Parameters

command

string

payload?

unknown

Returns

boolean


context()

context(): Ctx

Defined in: modal/engine.ts:266

The current context (world facts — inputs, not choices; see setContext).

Returns

Ctx


dispatch()

dispatch(command, payload?): EngineState

Defined in: modal/engine.ts:273

Run one command through the reducer and commit. Returns the new state. Unknown command → throws (loudly; commands are code, not user input). A dispatch from inside a subscriber is queued and runs after the current commit completes (single-writer linearity; it returns the pre-state).

Parameters

command

string

payload?

unknown

Returns

EngineState


emit()

emit(event, payload?): EngineState

Defined in: modal/engine.ts:284

Fire a declared system-event binding; unbound events are ignored.

Parameters

event

string

payload?

unknown

Returns

EngineState


setContext()

setContext(patch): void

Defined in: modal/engine.ts:290

Replace world facts (tab identity, grants, connection, selection). Facts are not choices: no command sets them, they are never durable — but claims derive from them, so subscribers are notified.

Parameters

patch

Partial<Ctx>

Returns

void


state()

state(): EngineState

Defined in: modal/engine.ts:264

The committed state — a frozen plain object; reads are never stale.

Returns

EngineState


subscribe()

subscribe(listener): () => void

Defined in: modal/engine.ts:292

Notified after every commit (dispatch that changed state, or context).

Parameters

listener

(state, event) => void

Returns

() => void