From d7bff640985036fedcc7aebc24171b0e6e5c49bf Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 16 Oct 2024 15:30:47 -0300 Subject: [PATCH] update docs --- plugins/store/guest-js/index.ts | 57 +++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/plugins/store/guest-js/index.ts b/plugins/store/guest-js/index.ts index dfa34ae9..07bfa162 100644 --- a/plugins/store/guest-js/index.ts +++ b/plugins/store/guest-js/index.ts @@ -33,10 +33,24 @@ export type StoreOptions = { } /** + * Create a new store. + * + * If the store already exists, its data will be overwritten. + * + * To load the store if it already exists you must use {@link load} instead. + * + * If the store is already loaded you must use {@link getStore} instead. + * + * @example + * ```typescript + * import { Store } from '@tauri-apps/api/store'; + * const store = await Store.create('store.json'); + * ``` + * * @param path Path to save the store in `app_data_dir` * @param options Store configuration options * - * @throws If a store at that path already exists + * @throws If a store at that path is already loaded */ export async function create( path: string, @@ -48,12 +62,21 @@ export async function create( /** * Create a new Store or load the existing store with the path. * - * If the store at the given path is already loaded, - * its instance is returned regardless of the options object. - * If the settings to not match an error is returned. + * If the store is already loaded you must use {@link getStore} instead. + * + * @example + * ```typescript + * import { Store } from '@tauri-apps/api/store'; + * let store = await Store.get('store.json'); + * if (!store) { + * store = await Store.load('store.json'); + * } + * ``` * * @param path Path to save the store in `app_data_dir` * @param options Store configuration options + * + * @throws If a store at that path is already loaded */ export async function load( path: string, @@ -63,7 +86,24 @@ export async function load( } /** - * @param path Path of the store + * Gets an already loaded store. + * + * If the store is not loaded, returns `null`. In this case, + * you must either {@link Store.create | create} it or {@link Store.load load} it. + * + * This function is more useful when you already know the store is loaded + * and just need to access its instance. Prefer {@link Store.load} otherwise. + * + * @example + * ```typescript + * import { getStore } from '@tauri-apps/api/store'; + * let store = await getStore('store.json'); + * if (!store) { + * store = await Store.load('store.json'); + * } + * ``` + * + * @param path Path of the store. */ export async function getStore(path: string): Promise { return await Store.get(path) @@ -193,7 +233,7 @@ export class Store extends Resource implements IStore { * @param path Path to save the store in `app_data_dir` * @param options Store configuration options * - * @throws If a store at that path already exists + * @throws If a store at that path is already loaded */ static async create(path: string, options?: StoreOptions): Promise { const rid = await invoke('plugin:store|create_store', { @@ -219,6 +259,8 @@ export class Store extends Resource implements IStore { * * @param path Path to save the store in `app_data_dir` * @param options Store configuration options + * + * @throws If a store at that path is already loaded */ static async load(path: string, options?: StoreOptions): Promise { const rid = await invoke('plugin:store|load', { @@ -234,6 +276,9 @@ export class Store extends Resource implements IStore { * If the store is not loaded, returns `null`. In this case, * you must either {@link Store.create | create} it or {@link Store.load load} it. * + * This function is more useful when you already know the store is loaded + * and just need to access its instance. Prefer {@link Store.load} otherwise. + * * @example * ```typescript * import { Store } from '@tauri-apps/api/store';