reearth.data
The reearth.data
namespace provides methods to manage client-side storage in reearth
plugins. It allows asynchronous retrieval, updating, and deletion of data, as well as managing storage keys and clearing the entire store. This namespace is useful for persisting user preferences, session data, or temporary settings.
reearth.data.clientStorage
The clientStorage offers an interface for managing a lightweight, asynchronous key-value storage system. It provides several methods for interacting with the plugin’s client-side storage, including reading, writing, and deleting data.
setAsync
Stores a key-value pair in the storage.
Syntax
Parameters
key
Type string
The key to associate with the value.
value
Type any
The value to store.
Return Value
Type Promise<void>
A promise that resolves when the key-value pair is saved.
Example
getAsync
Retrieves the value associated with a specific key.
Syntax
Parameters
key
Type string
The key of the value to retrieve.
Return Value
Type Promise<any>
A promise that resolves with the value associated with the key, or undefined if the key doesn’t exist.
Example
keysAsync
Retrieves all keys stored in the client storage.
Syntax
Return Value
Type Promise<string[]>
A promise that resolves with an array of strings, each representing a key.
Example
deleteAsync
Removes a key-value pair from the storage.
Syntax
Parameters
key
Type string
The key of the value to delete.
Return Value
Type Promise<void>
A promise that resolves when the key-value pair is deleted.
Example
dropStoreAsync
Clears all data from the client storage.
Syntax
Return Value
Type Promise<void>
A promise that resolves when the storage is cleared.