This Store is actually a wrapper over the tauri-plugin-store. Customized to be used with Jarvis Extensions, the APIs are exactly the same. A key-value store for Jarvis Extensions. Create a store in UI Extensions to store any data. filename is optional for the constructor if you only need one store file. If you plan to have multiple stores, e.g. one for settings, one for data, you can specify different filenames.

const store = new JarvisStore("settings.bin");
await store.set("theme", "dark");
const theme = await store.get("theme");
console.log(theme); // dark

Constructors

  • filename is optional if you only need one store file. If you plan to have multiple stores, e.g. one for settings, one for data, you can specify different filenames.

    Parameters

    • filename: string = "default.bin"

      filename for the store. Defaults to default.bin.

    Returns JarvisStore

    const store = new JarvisStore("settings.bin");
    await store.set("theme", "dark");
    const theme = await store.get("theme");
    console.log(theme); // dark

Properties

path: string

Methods

  • Clears the store, removing all key-value pairs.

    Note: To clear the storage and reset it to it's default value, use reset instead.

    Returns Promise<void>

  • Returns the value for the given key or null the key does not exist.

    Type Parameters

    • T

    Parameters

    • key: string

    Returns Promise<null | T>

  • Attempts to load the on-disk state at the stores 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 does not emit change events.

    Returns Promise<void>

  • Listen to changes on the store.

    Type Parameters

    • T

    Parameters

    • cb: (key: string, value: null | T) => void

    Returns Promise<UnlistenFn>

    A promise resolving to a function to unlisten to the event.

  • Listen to changes on a store key.

    Type Parameters

    • T

    Parameters

    • key: string
    • cb: (value: null | T) => void

    Returns Promise<UnlistenFn>

    A promise resolving to a function to unlisten to the event.

  • Resets the store to it's default value.

    If no default value has been set, this method behaves identical to clear.

    Returns Promise<void>

  • Saves the store to disk at the stores path.

    As the store is only persisted to disk before the apps exit, changes might be lost in a crash. This method lets you persist the store to disk whenever you deem necessary.

    Returns Promise<void>

  • Inserts a key-value pair into the store.

    Parameters

    • key: string
    • value: unknown

    Returns Promise<void>