io.contexts API
The Shared Contexts API for global state synchronization between applications.
set()
Create a new shared context or replace the value of an existing one entirely.
io.contexts.set(name: string, data: object): Promise<void>
| Parameter | Type | Description |
|---|---|---|
namerequired | string | Unique context name. |
datarequired | object | The context data object. Replaces the entire context. |
Example
await io.contexts.set("SelectedClient", { name: "Jane", id: "C-101" });update()
Merge properties into an existing context. Creates if it doesn't exist. Set a property to null to remove it.
io.contexts.update(name: string, data: object): Promise<void>
Example
await io.contexts.update("SelectedClient", { portfolio: { total: 1250000 } });
// Remove a key
await io.contexts.update("SelectedClient", { portfolio: null });get()
Get the current value of a shared context.
io.contexts.get(name: string): Promise<object>
Example
const data = await io.contexts.get("SelectedClient");subscribe()
Subscribe to changes on a shared context. The callback fires immediately with the current value, then on each update.
io.contexts.subscribe(name: string, callback: (data, delta, removed, unsubscribe, extraData) => void): Promise<() => void>
| Parameter | Type | Description |
|---|---|---|
namerequired | string | Context name to subscribe to. |
callbackrequired | function | Called on every context update. Receives: data (full context), delta (changed properties), removed (removed keys). |
Example
const unsub = await io.contexts.subscribe("SelectedClient", (data, delta) => {
console.log("Context updated:", data);
});
// Cleanup
unsub();setPath()
Set a deeply nested property using a dot-notation path.
io.contexts.setPath(name: string, path: string, value: any): Promise<void>
Example
await io.contexts.setPath("SelectedClient", "portfolio.holdings[0].quantity", 500);all()
Returns an array of all available context names.
io.contexts.all(): string[]
destroy()
Permanently remove a shared context.
io.contexts.destroy(name: string): Promise<void>