Skip to main content

State

interface

A read-only handle to one state value. Returned by `ctx.state('editor.selection')` and the other built-in state names. Reading `.value` gives you the current data, and it tracks: inside an `effect` or a condition predicate, reading it registers a dependency. Use `getSnapshot()` when you want the data without that tracking, and `subscribe()` when you are outside a reactive body and need a callback. Built-in state is never writable from a mod. To change host state, dispatch the matching action with `ctx.action(id, input)`.

interface State<TValue>

Import

import { State } from '@modular/sdk/editor';

Members10

accessScope
HostScope

The scope this handle reads through: root, workspace, editor, and so on.

capturedAt
string

When the current value was committed, as an ISO timestamp.

descriptor
StateDescriptor

Title, owner, schema, scope, and sensitivity as the host sees them.

id
string & $brand<'HostStateId'>

Host-wide identifier, which for mod state includes the mod id.

kind
'state'
previous
StateVersion<TValue> | null

The value before the most recent write, or `null` if there was none.

revision
number

Counter that increases on every committed write.

value
TValue

Current value. Reading it inside a reactive body subscribes to it.

getSnapshot
() => StateSnapshot<TValue>

Read value, revision, and previous version together, without tracking.

subscribe
(listener: (snapshot: StateSnapshot<TValue>) => void) => () => void

Call `listener` on every write. Call the returned function to stop.

Notes

category
State