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
Section titled “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
Section titled “setAsync”Stores a key-value pair in the storage.
Syntax
Section titled “Syntax”reearth.data.clientStorage.setAsync(key: string, value: unknown): Promise<void>Parameters
Section titled “Parameters”Type string
The key to associate with the value.
Type unknown
The value to store.
Return Value
Section titled “Return Value”Type Promise<void>
A promise that resolves when the key-value pair is saved.
getAsync
Section titled “getAsync”Retrieves the value associated with a specific key.
Syntax
Section titled “Syntax”reearth.data.clientStorage.getAsync(key: string): Promise<unknown>Parameters
Section titled “Parameters”Type string
The key of the value to retrieve.
Return Value
Section titled “Return Value”Type Promise<unknown>
A promise that resolves with the value associated with the key, or undefined if the key doesn’t exist.
keysAsync
Section titled “keysAsync”Retrieves all keys stored in the client storage.
Syntax
Section titled “Syntax”reearth.data.clientStorage.keysAsync(): Promise<string[]>Return Value
Section titled “Return Value”Type Promise<string[]>
A promise that resolves with an array of strings, each representing a key.
deleteAsync
Section titled “deleteAsync”Removes a key-value pair from the storage.
Syntax
Section titled “Syntax”reearth.data.clientStorage.deleteAsync(key: string): Promise<void>Parameters
Section titled “Parameters”Type string
The key of the value to delete.
Return Value
Section titled “Return Value”Type Promise<void>
A promise that resolves when the key-value pair is deleted.
dropStoreAsync
Section titled “dropStoreAsync”Clears all data from the client storage.
Syntax
Section titled “Syntax”reearth.data.clientStorage.dropStoreAsync(): Promise<void>Return Value
Section titled “Return Value”Type Promise<void>
A promise that resolves when the storage is cleared.