Update or delete a key-value pair in the store.
Changes are automatically persisted and synchronized across all instances with the same namespace via KOS topics.
The key to update or delete
The value to set (string | number | boolean), or undefined to delete the key
Promise that resolves when the operation completes
// Set a value
await keyValue.updateState('theme', 'dark');
// Delete a key
await keyValue.updateState('theme', undefined);
Topic handler for /keyVal/set events to sync updates across instances.
Automatically called when any KeyValue model instance updates a value, ensuring all instances with the same namespace stay synchronized.
The key-value update event containing namespace, key, and new value
Topic handler for /keyVal/remove events to sync deletions across instances.
Automatically called when any KeyValue model instance deletes a key, ensuring all instances with the same namespace stay synchronized.
The key-value update event containing namespace and deleted key
Key-Value Model - Persistent, reactive state storage with real-time synchronization across KOS applications.
This model provides a namespaced key-value store that automatically persists data and synchronizes changes across all connected clients in real-time. Perfect for storing user preferences, application state, feature flags, or any data that needs to persist between sessions and sync across instances.
Key Features
Topic-Based Reactivity
The model listens to two KOS topics for real-time synchronization:
/keyVal/set- Fired when any key-value pair is updated or added/keyVal/remove- Fired when a key is deleted from the storeThese topics ensure that all instances of the model with the same namespace stay synchronized across browser tabs, windows, and even different client applications. The model automatically filters events by namespace to ensure isolation.
Example: Basic Usage
Example: React Integration
Use Declared Type
See