Skip to content

Commit d7bff64

Browse files
committed
update docs
1 parent 983bd82 commit d7bff64

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

plugins/store/guest-js/index.ts

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,24 @@ export type StoreOptions = {
3333
}
3434

3535
/**
36+
* Create a new store.
37+
*
38+
* If the store already exists, its data will be overwritten.
39+
*
40+
* To load the store if it already exists you must use {@link load} instead.
41+
*
42+
* If the store is already loaded you must use {@link getStore} instead.
43+
*
44+
* @example
45+
* ```typescript
46+
* import { Store } from '@tauri-apps/api/store';
47+
* const store = await Store.create('store.json');
48+
* ```
49+
*
3650
* @param path Path to save the store in `app_data_dir`
3751
* @param options Store configuration options
3852
*
39-
* @throws If a store at that path already exists
53+
* @throws If a store at that path is already loaded
4054
*/
4155
export async function create(
4256
path: string,
@@ -48,12 +62,21 @@ export async function create(
4862
/**
4963
* Create a new Store or load the existing store with the path.
5064
*
51-
* If the store at the given path is already loaded,
52-
* its instance is returned regardless of the options object.
53-
* If the settings to not match an error is returned.
65+
* If the store is already loaded you must use {@link getStore} instead.
66+
*
67+
* @example
68+
* ```typescript
69+
* import { Store } from '@tauri-apps/api/store';
70+
* let store = await Store.get('store.json');
71+
* if (!store) {
72+
* store = await Store.load('store.json');
73+
* }
74+
* ```
5475
*
5576
* @param path Path to save the store in `app_data_dir`
5677
* @param options Store configuration options
78+
*
79+
* @throws If a store at that path is already loaded
5780
*/
5881
export async function load(
5982
path: string,
@@ -63,7 +86,24 @@ export async function load(
6386
}
6487

6588
/**
66-
* @param path Path of the store
89+
* Gets an already loaded store.
90+
*
91+
* If the store is not loaded, returns `null`. In this case,
92+
* you must either {@link Store.create | create} it or {@link Store.load load} it.
93+
*
94+
* This function is more useful when you already know the store is loaded
95+
* and just need to access its instance. Prefer {@link Store.load} otherwise.
96+
*
97+
* @example
98+
* ```typescript
99+
* import { getStore } from '@tauri-apps/api/store';
100+
* let store = await getStore('store.json');
101+
* if (!store) {
102+
* store = await Store.load('store.json');
103+
* }
104+
* ```
105+
*
106+
* @param path Path of the store.
67107
*/
68108
export async function getStore(path: string): Promise<Store | null> {
69109
return await Store.get(path)
@@ -193,7 +233,7 @@ export class Store extends Resource implements IStore {
193233
* @param path Path to save the store in `app_data_dir`
194234
* @param options Store configuration options
195235
*
196-
* @throws If a store at that path already exists
236+
* @throws If a store at that path is already loaded
197237
*/
198238
static async create(path: string, options?: StoreOptions): Promise<Store> {
199239
const rid = await invoke<number>('plugin:store|create_store', {
@@ -219,6 +259,8 @@ export class Store extends Resource implements IStore {
219259
*
220260
* @param path Path to save the store in `app_data_dir`
221261
* @param options Store configuration options
262+
*
263+
* @throws If a store at that path is already loaded
222264
*/
223265
static async load(path: string, options?: StoreOptions): Promise<Store> {
224266
const rid = await invoke<number>('plugin:store|load', {
@@ -234,6 +276,9 @@ export class Store extends Resource implements IStore {
234276
* If the store is not loaded, returns `null`. In this case,
235277
* you must either {@link Store.create | create} it or {@link Store.load load} it.
236278
*
279+
* This function is more useful when you already know the store is loaded
280+
* and just need to access its instance. Prefer {@link Store.load} otherwise.
281+
*
237282
* @example
238283
* ```typescript
239284
* import { Store } from '@tauri-apps/api/store';

0 commit comments

Comments
 (0)