Describe the settings with a schema, and contribute it with AppCapabilities.Settings. The app renders a form for
it on the settings page, using each field’s title, and syncs the values. KvsStore.make gives an atom that holds
the values, with defaults for a first run.
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Declared fields may be inherited and are copied to own properties in the
output. The __proto__ field is accepted only when it is an own property.
Parsing does not guarantee that output keys retain their input order.
Returns a new struct with the fields modified by the provided function.
Details
Options:
unsafePreserveChecks - if true, keep any .check(...) constraints
that were attached to the original union. Defaults to false.
Warning: This is an unsafe operation. Since mapFields
transformations change the schema type, the original refinement functions
may no longer be valid or safe to apply to the transformed schema. Only
use this option if you have verified that your refinements remain correct
after the transformation.
Helper to define a capability module with explicit typing.
Wraps the default export function to provide better type inference and make the pattern explicit.
This helper provides explicit typing for the module activation function,
making it clear that the function should:
Access declared requires via yield* (or the ambient Capability.Service/Plugin.Service)
Creates a KVS-backed atom for structured settings using Atom.kvs.
The entire object is stored as a single localStorage key with JSON serialization.
@param ― options.key - The localStorage key to store the value under.
@param ― options.schema - Effect Schema for the value type.
@param ― options.defaultValue - Function returning the default value.
@param ― options.runtime - Optional custom Atom runtime (defaults to localStorage).
@returns ― A writable atom that persists to localStorage.
@idiom ― org.dxos.effect.kvsStore
applies: Persisting a plugin's settings/config as one schema-validated localStorage blob (a global user preference set infrequently)
instead-of: hand-rolled localStorage reads/writes, or scattering per-field atoms, or using this for per-context UI state
uses: createKvsStorerelated: org.dxos.react-ui-attention.viewState
Device state is the plugin’s own capability. Declare a singleton on the plugin’s namespace and store it under the
key ${key}.state, so it stays on this device.
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Declared fields may be inherited and are copied to own properties in the
output. The __proto__ field is accepted only when it is an own property.
Parsing does not guarantee that output keys retain their input order.
Returns a new struct with the fields modified by the provided function.
Details
Options:
unsafePreserveChecks - if true, keep any .check(...) constraints
that were attached to the original union. Defaults to false.
Warning: This is an unsafe operation. Since mapFields
transformations change the schema type, the original refinement functions
may no longer be valid or safe to apply to the transformed schema. Only
use this option if you have verified that your refinements remain correct
after the transformation.
A singleton capability with identifier <key>.capability.<name>.
makeSingleton<
typeReturnType<Textends (...args: any) =>any> = Textends (...args: any) => infer R ? R : any
Obtain the return type of a function type
ReturnType<typeof
constmakeState: () =>Writable<{}, {}>
makeState>>()('state');
15
16
const
constmakeState: () =>Writable<{}, {}>
makeState = () =>
17
import KvsStore
KvsStore.
make<{}>(options: {
key: string;
schema: Schema.Codec<{}, any, never, never>;
defaultValue: () => {};
runtime?: ReturnType<typeof runtime>;
}): Writable<{}, {}>
export make
Creates a KVS-backed atom for structured settings using Atom.kvs.
The entire object is stored as a single localStorage key with JSON serialization.
@param ― options.key - The localStorage key to store the value under.
@param ― options.schema - Effect Schema for the value type.
@param ― options.defaultValue - Function returning the default value.
@param ― options.runtime - Optional custom Atom runtime (defaults to localStorage).
@returns ― A writable atom that persists to localStorage.
@idiom ― org.dxos.effect.kvsStore
applies: Persisting a plugin's settings/config as one schema-validated localStorage blob (a global user preference set infrequently)
instead-of: hand-rolled localStorage reads/writes, or scattering per-field atoms, or using this for per-context UI state
uses: createKvsStorerelated: org.dxos.react-ui-attention.viewState
Helper to define a capability module with explicit typing.
Wraps the default export function to provide better type inference and make the pattern explicit.
This helper provides explicit typing for the module activation function,
making it clear that the function should:
Access declared requires via yield* (or the ambient Capability.Service/Plugin.Service)
Both are atoms. A component reads one with useAtomValue and writes it with useAtomSet, after getting it with
useCapability. Other modules read them the same way they read any capability.