State and resource API
Typed definitions, effects, subscriptions and resource leases.
Signatures come from public package exports. Descriptions are checked against current JSDoc; identifiers retain their original names.
Create a state slot
Returns a slot installed through addState.
@quirekit/msfe-core@param definition - Pure document-local reducer and explicit inverse policy. @returns Reusable installable state slot.
function defineState<T>(definition: StateDefinition<T>): StateSlot<T>Pure reducers
See Transaction state for a complete module and updates.
@quirekit/msfe-coreTransaction-owned state; initialization is per document, not per definition.
export interface StateDefinition<T> {
readonly key: string;
readonly create: (document: SourceDocument) => T;
readonly update: (value: T, update: StateUpdate) => T;
readonly invert?: (value: T, update: StateUpdate) => readonly StateEffect<unknown>[];
}Effect tokens
Positional payloads need mapping; an effect alone does not define undo.
@quirekit/msfe-core@param map - Optional mapping for positional payloads. @returns Typed transaction effect token.
function defineEffect<T>(map?: (value: T, changes: ChangeDesc) => T | undefined): Effect<T>Transaction metadata
Use for correlation, not persistent document fields.
@quirekit/msfe-core@returns Typed metadata token without a second transaction store.
function defineMetadata<T>(): Metadata<T>Accepted-state subscriptions
Keep select pure and bounded; read the initial value separately.
@quirekit/msfe-coreAccepted-state subscription, with no speculative draft notifications.
export interface StateSubscription<T> {
readonly select: (state: EditorState) => T;
readonly change: (next: T, previous: T) => void;
readonly equal?: (a: T, b: T) => boolean;
}Resource leases
Used by TaskScope.acquire; see Resources for lifetime rules.
@quirekit/msfe-coreOne owned resource; each acquisition must return its own lease.
export interface ResourceLease<T> {
readonly value: T;
readonly release?: () => void;
}