Storage Object
Storage Object Documentation
Description
The Storage
object provides an in-memory key-value storage system that synchronizes with a remote service using the Roboqo
RPC interface. It supports both local and session storage types and provides methods to manipulate stored data efficiently. You can access storage via localStorage and sessionStorage global objects.
Methods
setItem
setItem
Description
Stores a value associated with a key and synchronizes it with the remote storage.
Signature
setItem(key: string, value: any): void
Parameters
key
(string
): The key under which the value is stored.value
(any
): The value to store.
Example Usage
localStorage.setItem("username", "JohnDoe");
getItem
getItem
Description
Retrieves a stored value by its key.
Signature
getItem(key: string): any
Parameters
key
(string
): The key to retrieve the stored value.
Returns
T | null
: The stored value ornull
if the key does not exist.
Example Usage
const username = localStorage.getItem("username");
console.log(username); // Output: "JohnDoe"
removeItem
removeItem
Description
Removes a value from storage and synchronizes the removal with the remote storage.
Signature
removeItem(key: string): void
Parameters
key
(string
): The key to remove.
Example Usage
localStorage.removeItem("username");
clear
clear
Description
Clears all stored data and synchronizes the removal with the remote storage.
Signature
clear(): void
Example Usage
storage.clear();
keys
keys
Description
Retrieves an array of all stored keys.
Signature
keys(): string[]
Returns
string[]
: An array of stored keys.
Example Usage
const storedKeys = localStorage.keys();
console.log(storedKeys);
toJSON
toJSON
Description
Converts the stored data into a JSON object.
Signature
toJSON(): Record<string, any>
Returns
Record<string, any>
: An object representation of the stored data.
Example Usage
const jsonData = localStorage.toJSON();
console.log(jsonData);
Example Usage
localStorage.setItem("username", "Alice");
console.log(localStorage.getItem("username")); // Output: "Alice"
localStorage.removeItem("username");
localStorage.clear();
Last updated