kv — Stored state
Persist private settings and state for your plugin.
Table of content
Capability: kv · Available in: workspace and live preview.
Main methods
| Method | Purpose |
|---|---|
this.kv.read(key, true) |
Return an array of value handles for a key |
this.kv.write(key, true, value) |
Create a stored value and return its handle |
handle.update(value) |
Replace a stored value |
handle.delete() |
Delete a stored value |
handle.destroy() |
Release the local handle without deleting stored data |
this.kv.onKeyEvent(key, true, type, listener) |
Subscribe to changes for a key |
this.kv.offKeyEvent(key, true, type, listener) |
Remove a key subscription |
const values = await this.kv.read('settings', true);
if (values.length) {
await values[0].update({ color: 'blue' });
values.forEach(value => value.destroy());
} else {
const value = await this.kv.write('settings', true, { color: 'blue' });
value.destroy();
}
Scope and limits
Values belong to the current user and plugin, and survive stopping the plugin or reloading Emberly. Use true for the historical isPrivate argument; shared storage behavior is not implemented.
Keys must be nonempty and at most 128 characters. Values must be JSON-serializable and at most 64 KiB. Writing creates a new value rather than replacing an existing one; read and update the existing handle when maintaining a single setting.