Skip to main content

OwnedState

interface

A writable handle to state your own mod declared. Returned by `ctx.state(declaration)` when you pass the value you built with state. This is the only writable state handle: pass a built-in name instead and you get a plain read-only State.

interface OwnedState<TValue>

Import

import { OwnedState } from '@modular/sdk/view';

Members11

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
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.

set()
(value: TValue, options?: StateSetOptions) => Promise<void>

Write a new value and wait for the host to commit it. The value is validated against the declaration's type first, so a write that does not match rejects instead of storing bad data.

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

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