State
interfaceA 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)`.
Import
import { State } from '@modular/sdk/canvas';Members10
- accessScope
HostScopeThe scope this handle reads through: root, workspace, editor, and so on.
- capturedAt
stringWhen the current value was committed, as an ISO timestamp.
- descriptor
StateDescriptorTitle, 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> | nullThe value before the most recent write, or `null` if there was none.
- revision
numberCounter that increases on every committed write.
- value
TValueCurrent 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) => () => voidCall `listener` on every write. Call the returned function to stop.
Notes
- category
- State