Skip to content

Cheatsheet

Every term and concept in @dunky-dev/state-machine, with a one-line meaning and a link to its full doc page.

TermMeaning
machineThe built service from machine(config) — exposes start/stop/send/state/context/select.
setupThe authoring entry point — setup().createMachine(literal) (lightweight) or setup<Ctx,Ev>().config(registries).createMachine(config) (names compile-checked).
stateOne of the flat, named situations the machine can be in (exactly one at a time).
transitionAn on entry: where an event takes the machine — optional target, guard, actions.
eventThe { type, … } object you send() to drive a transition.
contextThe machine’s data: one plain object, read directly (m.context.x), written via setContext.
setContextThe single, batched entry point for writing context (shallow-equal deduped).
sendDispatch an event to the machine; events run to completion.
TermMeaning
guardA predicate that gates a transition — return false and it doesn’t fire.
and / or / notGuard combinators for composing named guards.
fallthroughAn array of transitions for one event; the first whose guard passes wins.
actionA fire-and-forget side-effect run on a transition, in order — gets {context, setContext, event, send, computed}.
actWrite-sugar returning a context-writing action — act({ field: value }) instead of the setContext wrapper.
oneOfConditional action: variadic { guard?, actions } branches, first passing wins (the action analog of fallthrough).
entry / exitActions run when a state is entered / left (any path in or out).
run-to-completionEvents queue: a send() inside an action waits until the current transition finishes — no re-entrancy.
TermMeaning
afterA timed transition — fires after a delay while in a state; auto-cancelled on exit.
delayAn after key: a number of ms, or a named delay from implementations.delays (can read context).
watchRun actions whenever a context/computed field changes — in any state, for the machine’s lifetime.
computedA lazy, memoized value derived from context (or other computeds); recomputes only when a read input changes.
TermMeaning
effectA side-effect with cleanup, scoped to a state: runs on enter, its returned cleanup runs on exit.
ComponentEffectA platform-specific effect declared outside the machine — touches the DOM or reads props, calls send() into the machine.
implementationsThe named registry on a config — guards / actions / effects / delays referenced by string.
TermMeaning
connectA pure function mapping a machine snapshot → the view-facing api (handlers + attributes).
connectorKeeps connect live: memoizes the snapshot, makes props a reactive input, wires reactions.
snapshotThe memoized view api the connector serves — stable identity until the machine or props change.
setPropsPush new props into the connector (a reactive input; shallow-dedup’d).
reactionA [selector, callback] tuple that fires a prop-callback from outside the machine on a value change.
makeReactionInference helper for a reaction tuple — recovers the selector→callback Value type link.
bindingsThe agnostic event/attr vocabulary connect speaks — onPress, role, describedBy.
normalizeThe per-target step translating bindings → real props (onPressonClick; aria-* on web).
the machine never sees propsThe defining rule: a machine is pure behavior; props live only at the edge.
the edgeWhere props/platform meet the machine — the connector (reactions) + the target’s ComponentEffect (platform listeners).
TermMeaning
subscribeCoarse observation — fires on any state/context change (what a useSyncExternalStore bridge uses).
selectFine-grained observation — narrows to a slice, fires only when that value changes.
selectionWhat select(...) returns: a value-deduped view with .value + .subscribe.
TermMeaning
composeRun several peer machines as one unit (orthogonal regions) — the answer to “nested/parallel” without nesting.
compositionWhat compose(...) returns: bundled start/stop plus sync + combine.
syncA coarse cross-region rule on a composition — runs when any member changes.
combineA value-deduped selection derived across composition members.
tagsLabels on states so consumers query a category (hasTag('visible')) instead of a name.
hasTagCheck whether the current state carries a tag.
matchesExact-state check — m.matches('open').
createStoreA tiny reactive cell (value + listeners) for singleton state outside any one machine.
storeWhat createStore(...) returns: get / set / subscribe (+ optional domain methods).
TermMeaning
start / stopBoot / tear down the machine — effects, watchers, and reactions begin / clean up.
onStart / onStopHang start/stop-scoped work off the machine’s lifecycle (how the connector wires reactions).
MACHINE_INITThe synthetic event fired when effects/watchers boot on start().
context ownershipOne plain object per machine, copied from the config at construction, mutated in place — its identity never changes.