Skip to main content

Operations on Store

There are two kinds of stores global (realtime) and local (accessible only to the person who created them). You can perform CRUD operations on each store.

const store = plugin.stores.create('myStore');

Get store name

const name = store.name;

Check if store is local

const isLocal = store.isLocal;

Set a value

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier used to store value.-true
valueanyData to be set.-true
await store.set('key', { ... });

Update a value

Updates an already existing value in the store. If the stored value is ['a', 'b'], the operation store.update('key', ['c']) will modify the value to ['a','b','c'].

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier used to update value.-true
valueanyData to be updated.-true
await store.update('key', { ... });

Get a value

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier used to get a value.-true
store.get('key');

Delete a value

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier used to delete a value.-true
await store.delete('key');

Get all data

store.getAll();

Subscribe to data change

Attaches an event listener on store key's to listen for data change on a specific key. Ideally called just after store is created.

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier.-true
store.subscribe('key', () => { ... });

Unsubscribe to data change

Removes all event listeners attached to a store key.

ParamTypeDescriptionDefault ValueRequired
keystringUnique identifier.-true
store.unsubscribe('key');