PreferenceStore
Store validated announcement preferences with optional persistence.
createPreferenceStore
createPreferenceStore validates loaded and assigned values before exposing a stable snapshot.
import { createPreferenceStore } from "@generative-a11y/dom";
const store = createPreferenceStore();
store.setPreferences({
version: 1,
preset: "balanced",
streaming: "sentence",
tools: "status",
});
// Read store.getSnapshot() or subscribe to changes.
// Call store.dispose() when its owner ends.Persistence is disabled by default. Supply persistence.key to use browser
storage when it is available:
const store = createPreferenceStore({
persistence: { key: "chat:a11y-preferences" },
});Use preferencesToCoreConfiguration to map the snapshot to a core preset and
policy overrides. Unsubscribe listeners and dispose the store when its owner
ends.
Options
Prop
Type
Custom storage and runtime configuration
Supply storage and events together to persist and synchronize through a
custom storage layer. When you inject storage, the store uses only the event
source you provide.
import { createRuntime } from "@generative-a11y/core";
import { preferencesToCoreConfiguration } from "@generative-a11y/dom";
const runtime = createRuntime(
preferencesToCoreConfiguration(store.getSnapshot()),
);
// Call runtime.dispose() when its owner ends.Core reads this configuration at construction. Later preference changes update the store without changing an active runtime. A11yProvider also uses preferences only when constructing its owned runtime, and only when no explicit preset or policy is supplied. Apply saved changes when creating the next runtime or remounting the provider at an intentional session boundary.
PreferenceSchemaV1 and helpers
A version field makes persistence migrations explicit.
Prop
Type