LazyStore
Module @netwiv/api/plugins/store · Kind Class
import { LazyStore } from '@netwiv/api/plugins/store';A lazy loaded key-value store persisted by the backend layer.
Constructor
Section titled “Constructor”new LazyStore(path: string, options?: StoreOptions | undefined)Instance members
Section titled “Instance members”clear(): Promise<void>Clears the store, removing all key-value pairs.
Note: To clear the storage and reset it to its default value, use {@linkcode reset} instead.
close(): Promise<void>Close the store and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.
delete
Section titled “delete”delete(key: string): Promise<boolean>Removes a key-value pair from the store.
entries
Section titled “entries”entries<T>(): Promise<[key: string, value: T][]>Returns a list of all entries in the store.
get<T>(key: string): Promise<T | undefined>Returns the value for the given key or undefined if the key does not exist.
has(key: string): Promise<boolean>Returns true if the given key exists in the store.
init(): Promise<void>Init/load the store if it’s not loaded already
keys(): Promise<string[]>Returns a list of all keys in the store.
length
Section titled “length”length(): Promise<number>Returns the number of key-value pairs in the store.
onChange
Section titled “onChange”onChange<T>(cb: (key: string, value: T | undefined): void) => Promise<UnlistenFn>Listen to changes on the store.
onKeyChange
Section titled “onKeyChange”onKeyChange<T>(key: string, cb: (value: T | undefined): void) => Promise<UnlistenFn>Listen to changes on a store key.
options?
Section titled “options?”readonly options?: anyreadonly path: anyreload
Section titled “reload”reload(options?: ReloadOptions | undefined): Promise<void>Attempts to load the on-disk state at the store’s path into memory.
This method is useful if the on-disk state was edited by the user and you want to synchronize the changes.
Note:
- This method loads the data and merges it with the current store,
this behavior will be changed to resetting to default first and then merging with the on-disk state in v3,
to fully match the store with the on-disk state, set {@linkcode ReloadOptionsignoreDefaults} to
true - This method does not emit change events.
reset(): Promise<void>Resets the store to its default value.
If no default value has been set, this method behaves identical to {@linkcode clear}.
save(): Promise<void>Saves the store to disk at the store’s path.
set(key: string, value: unknown): Promise<void>Inserts a key-value pair into the store.
store: anyvalues
Section titled “values”values<T>(): Promise<T[]>Returns a list of all values in the store.
Descriptions come from the pinned @tauri-apps/plugin-store@2.4.5 declarations (MIT OR Apache-2.0); imports are shown with @netwiv/api paths.