Storage

Storage

Utilises persistent storage outside of the webview for storing key value pairs.

Note: You must wait for the Agent to initialise before calling any of these methods.

Methods

(async) deleteItem() → {Promise}

Delete an item from storage

Example
import Agent from '@meldcx/agent';

const agent = new Agent();

const init = async() => {
     await agent.onReadyAsync();
     await agent.storage.deleteItem('myImportantKey');
     console.log('The item myImportantKey is deleted');
};

init();

(async) getItem() → {Object|Primative}

Get the value of a key

Example
import Agent from '@meldcx/agent';

const agent = new Agent();

const init = async() => {
     await agent.onReadyAsync();
     const value = await agent.storage.getItem('myImportantKey');

     console.log('The value of myImportantKey is:');
     console.log(value); // will print "myImportantValue"
};

init();

(async) setItem() → {Promise}

Store a key/value pair item into storage.

Example
import Agent from '@meldcx/agent';

const agent = new Agent();

const init = async() => {
     await agent.onReadyAsync();
     await agent.Storage.setItem('myImportantKey', 'myImportantValue');
     console.log('The key-value pair has been stored');
};

init();