ReadonlyappReadonlyappPending writes for the next tick. Cleared at the start of each pass.
ReadonlycheckpointsFiltered view of history: every checkpoint entry with its
history index appended. Allocates on read; for hot paths walk
history directly and filter inline.
ReadonlycursorIndex of the next history slot. Equals history.length unless scrubbed back via replay.
ReadonlyforksTails of history dropped by mutate-while-scrubbed-back, oldest
first. Each entry is a plain HistoryEntry[] plus the cursor
it forked from and a timestamp; restore by re-applying via
setValue / trigger. Capped by forkLimit.
ReadonlyhistoryAppend-only log of recorded mutations.
ReadonlyintentsSemantic element registry populated from data-intent="verb.noun".
Each intent maps to the array of elements currently carrying it.
Used by findByIntent() and surfaced in describe(). Lets agents
locate UI by purpose ("checkout.submit") instead of by selector.
ReadonlyrefsDOM handles registered via data-ref="name". Keyed by the ref name.
ReadonlyreplayingTrue while replay() is in flight.
ReadonlysnapshotsReplay-acceleration snapshots. Populated only when snapshotEvery is set.
Async resource. Sets ${path}.loading / ${path}.error /
${path}.data as the promise progresses. Each phase records
through setValue (so the round-trip lands in history; replay
re-applies the values without re-issuing the fetch). Returns the
run function for refetching; also indexed by path so
refresh(path) works without retaining the handle.
Subscribe a system to one or more paths. Returns an unsubscribe function.
Record an additive numeric change. Multiple addValues on the
same path within one tick accumulate against the prior value.
id defaults to add:${path}.
Optionalid: stringSpeculative execution. Drops a checkpoint, runs fn, returns a
handle the caller uses to commit (mark in history) or discard
(rewind cursor). fn may return a value or a Promise — the
caller awaits and decides.
Scan a DOM subtree for declarative bindings: {{expr}}, :attr="expr", data-if, data-each, data-key, data-model, data-ref, and data-action. Returns a destroy function that undoes every binding it set up.
Optionalroot: Element | DocumentRecord a tagged checkpoint into history. Pure marker — replay
walks past it without state effect. Use to mark logically atomic
boundaries (search complete, form submitted, wizard step done).
Fires onRecord. Replay-to-checkpoint:
spektrum.replay(spektrum.checkpoints.find(c => c.id === name).index + 1)
Optionalmetadata: anyFirst-class derived value. Primes synchronously from current state
on registration (so registering after deps are populated still
lands the initial value), then re-computes when any deps path
changes. Writes to both state and delta so mid-tick reads see
fresh values.
Operational manifest of the running instance. One JSON object containing state, registered systems, fns and their schemas, named refs, registered intents, checkpoints, and history shape. Cheap. The single best first call for an agent orienting itself.
Causal trace over a slice of history. Each entry is annotated
with the systems whose subscriptions intersect its path. Useful
for agents reconstructing why state moved. Note: subscriber set
is the CURRENT registry, not a historical record of who actually
fired.
Optionalopts: { from?: number; to?: number }Locate elements by their declared data-intent. Returns a copy
so the caller can iterate without racing the registry.
Subscribe an error handler. Called as (err, systemFn) whenever a
subscribed system throws inside tick(). Multiple handlers may be
registered; each call appends a subscriber and returns an
unsubscribe handle. Without any handler, errors fall through to
console.error. Pass null to clear every subscriber on this hook.
Subscribe a fork hook. Fires when a record() truncates history
(mutate-while-scrubbed-back), receiving the captured ForkRecord.
Descriptive: the truncate has already happened by the time the hook
runs; the dropped entries are accessible on forks and via the
hook argument. Multiple handlers may be registered; returns an
unsubscribe handle. Pass null to clear all subscribers.
Subscribe a post-record hook. Called synchronously with every
recorded HistoryEntry after it's been applied, snapshotted, and
trimmed. Does not fire during replay() (replay re-applies without
re-recording). Multiple handlers may be registered; returns an
unsubscribe handle. Pass null to clear all subscribers.
Re-run the loader previously registered via addAsync(path, …).
Returns the run Promise, or undefined when path was never
registered. Lets callers refetch without retaining the handle.
Detach the first system registered with fn. Returns true if removed.
Reset state and re-apply the first n recorded entries. O(K) when snapshotEvery is set.
Same as resetState(), but also clears systems registered via
addSystem. Built-in fns and hook registrations survive. Warns
when active systems are present at call time — silent detachment
has bitten users; call resetState() instead when you only want
to wipe state.
Wipe runtime state, refs, history, snapshots, forks. Preserves registered systems, defineFn entries, and hooks (onError, onRecord, onFork). Use this from library code that wants to clear state without nuking the host app's subscriptions.
rAF-driven tick pump. Reschedules itself every animation frame.
Serialize a portable snapshot of the instance. By default
includes state, history, and cursor so a fresh instance
can loadHistory it back to the same point. Pass
{ includeHistory: false } for a state-only snapshot;
{ includeForks: true } to also include preserved fork tails
(debug-only; forks aren't replay-restored by loadHistory).
Optionalopts: { includeForks?: boolean; includeHistory?: boolean }Record an absolute set. id defaults to set:${path} so the
entry stays locatable in history and explain(). Pairs with
addValue (same argument order) so authors can swap one for the
other without re-ordering.
Optionalid: stringRun one simulation step, draining the delta to quiescence.
Use Spektrum.addValue — same semantics with
a (path, value, id?) argument order that matches setValue.
trigger (id-first) is the pre-1.0 spelling, kept as a thin alias
for back-compat.
Conventional alias for addSystem. Same signature.
Committed state. Direct mutation persists; setValue/trigger go through the delta.