@@ -33,10 +33,24 @@ export type StoreOptions = {
33
33
}
34
34
35
35
/**
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
+ *
36
50
* @param path Path to save the store in `app_data_dir`
37
51
* @param options Store configuration options
38
52
*
39
- * @throws If a store at that path already exists
53
+ * @throws If a store at that path is already loaded
40
54
*/
41
55
export async function create (
42
56
path : string ,
@@ -48,12 +62,21 @@ export async function create(
48
62
/**
49
63
* Create a new Store or load the existing store with the path.
50
64
*
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
+ * ```
54
75
*
55
76
* @param path Path to save the store in `app_data_dir`
56
77
* @param options Store configuration options
78
+ *
79
+ * @throws If a store at that path is already loaded
57
80
*/
58
81
export async function load (
59
82
path : string ,
@@ -63,7 +86,24 @@ export async function load(
63
86
}
64
87
65
88
/**
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.
67
107
*/
68
108
export async function getStore ( path : string ) : Promise < Store | null > {
69
109
return await Store . get ( path )
@@ -193,7 +233,7 @@ export class Store extends Resource implements IStore {
193
233
* @param path Path to save the store in `app_data_dir`
194
234
* @param options Store configuration options
195
235
*
196
- * @throws If a store at that path already exists
236
+ * @throws If a store at that path is already loaded
197
237
*/
198
238
static async create ( path : string , options ?: StoreOptions ) : Promise < Store > {
199
239
const rid = await invoke < number > ( 'plugin:store|create_store' , {
@@ -219,6 +259,8 @@ export class Store extends Resource implements IStore {
219
259
*
220
260
* @param path Path to save the store in `app_data_dir`
221
261
* @param options Store configuration options
262
+ *
263
+ * @throws If a store at that path is already loaded
222
264
*/
223
265
static async load ( path : string , options ?: StoreOptions ) : Promise < Store > {
224
266
const rid = await invoke < number > ( 'plugin:store|load' , {
@@ -234,6 +276,9 @@ export class Store extends Resource implements IStore {
234
276
* If the store is not loaded, returns `null`. In this case,
235
277
* you must either {@link Store.create | create} it or {@link Store.load load} it.
236
278
*
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
+ *
237
282
* @example
238
283
* ```typescript
239
284
* import { Store } from '@tauri-apps/api/store';
0 commit comments