Skip to content

Commit 983bd82

Browse files
committed
rename newOrExisting to load, load to reload
1 parent 44016a4 commit 983bd82

File tree

10 files changed

+58
-59
lines changed

10 files changed

+58
-59
lines changed

plugins/store/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/store/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const COMMANDS: &[&str] = &[
66
"create_store",
7-
"new_or_existing",
7+
"load",
88
"get_store",
99
"close_store",
1010
"set",
@@ -17,7 +17,7 @@ const COMMANDS: &[&str] = &[
1717
"values",
1818
"entries",
1919
"length",
20-
"load",
20+
"reload",
2121
"save",
2222
];
2323

plugins/store/guest-js/index.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ export async function create(
5555
* @param path Path to save the store in `app_data_dir`
5656
* @param options Store configuration options
5757
*/
58-
export async function newOrExisting(
58+
export async function load(
5959
path: string,
6060
options?: StoreOptions
6161
): Promise<Store> {
62-
return await Store.newOrExisting(path, options)
62+
return await Store.load(path, options)
6363
}
6464

6565
/**
@@ -77,7 +77,7 @@ export class LazyStore implements IStore {
7777

7878
private get store(): Promise<Store> {
7979
if (!this._store) {
80-
this._store = newOrExisting(this.path, this.options)
80+
this._store = load(this.path, this.options)
8181
}
8282
return this._store
8383
}
@@ -180,6 +180,8 @@ export class Store extends Resource implements IStore {
180180
*
181181
* If the store already exists, its data will be overwritten.
182182
*
183+
* To load the store if it already exists you must use {@link load} instead.
184+
*
183185
* If the store is already loaded you must use {@link getStore} instead.
184186
*
185187
* @example
@@ -211,18 +213,15 @@ export class Store extends Resource implements IStore {
211213
* import { Store } from '@tauri-apps/api/store';
212214
* let store = await Store.get('store.json');
213215
* if (!store) {
214-
* store = await Store.newOrExisting('store.json');
216+
* store = await Store.load('store.json');
215217
* }
216218
* ```
217219
*
218220
* @param path Path to save the store in `app_data_dir`
219221
* @param options Store configuration options
220222
*/
221-
static async newOrExisting(
222-
path: string,
223-
options?: StoreOptions
224-
): Promise<Store> {
225-
const rid = await invoke<number>('plugin:store|new_or_existing', {
223+
static async load(path: string, options?: StoreOptions): Promise<Store> {
224+
const rid = await invoke<number>('plugin:store|load', {
226225
path,
227226
...options
228227
})
@@ -233,14 +232,14 @@ export class Store extends Resource implements IStore {
233232
* Gets an already loaded store.
234233
*
235234
* If the store is not loaded, returns `null`. In this case,
236-
* you must either {@link Store.create | create} it or {@link Store.newOrExisting newOrExisting} it.
235+
* you must either {@link Store.create | create} it or {@link Store.load load} it.
237236
*
238237
* @example
239238
* ```typescript
240239
* import { Store } from '@tauri-apps/api/store';
241240
* let store = await Store.get('store.json');
242241
* if (!store) {
243-
* store = await Store.newOrExisting('store.json');
242+
* store = await Store.load('store.json');
244243
* }
245244
* ```
246245
*
@@ -306,8 +305,8 @@ export class Store extends Resource implements IStore {
306305
return await invoke('plugin:store|length', { rid: this.rid })
307306
}
308307

309-
async load(): Promise<void> {
310-
await invoke('plugin:store|load', { rid: this.rid })
308+
async reload(): Promise<void> {
309+
await invoke('plugin:store|reload', { rid: this.rid })
311310
}
312311

313312
async save(): Promise<void> {

plugins/store/permissions/autogenerated/commands/new_or_existing.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-reload"
7+
description = "Enables the reload command without any pre-configured scope."
8+
commands.allow = ["reload"]
9+
10+
[[permission]]
11+
identifier = "deny-reload"
12+
description = "Denies the reload command without any pre-configured scope."
13+
commands.deny = ["reload"]

plugins/store/permissions/autogenerated/reference.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All operations are enabled by default.
1010

1111

1212
- `allow-create-store`
13-
- `allow-new-or-existing`
13+
- `allow-load`
1414
- `allow-get-store`
1515
- `allow-close-store`
1616
- `allow-set`
@@ -324,25 +324,25 @@ Denies the load command without any pre-configured scope.
324324
<tr>
325325
<td>
326326

327-
`store:allow-new-or-existing`
327+
`store:allow-reload`
328328

329329
</td>
330330
<td>
331331

332-
Enables the new_or_existing command without any pre-configured scope.
332+
Enables the reload command without any pre-configured scope.
333333

334334
</td>
335335
</tr>
336336

337337
<tr>
338338
<td>
339339

340-
`store:deny-new-or-existing`
340+
`store:deny-reload`
341341

342342
</td>
343343
<td>
344344

345-
Denies the new_or_existing command without any pre-configured scope.
345+
Denies the reload command without any pre-configured scope.
346346

347347
</td>
348348
</tr>

plugins/store/permissions/default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ All operations are enabled by default.
1212
"""
1313
permissions = [
1414
"allow-create-store",
15-
"allow-new-or-existing",
15+
"allow-load",
1616
"allow-get-store",
1717
"allow-close-store",
1818
"allow-set",

plugins/store/permissions/schemas/schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,14 @@
405405
"const": "deny-load"
406406
},
407407
{
408-
"description": "Enables the new_or_existing command without any pre-configured scope.",
408+
"description": "Enables the reload command without any pre-configured scope.",
409409
"type": "string",
410-
"const": "allow-new-or-existing"
410+
"const": "allow-reload"
411411
},
412412
{
413-
"description": "Denies the new_or_existing command without any pre-configured scope.",
413+
"description": "Denies the reload command without any pre-configured scope.",
414414
"type": "string",
415-
"const": "deny-new-or-existing"
415+
"const": "deny-reload"
416416
},
417417
{
418418
"description": "Enables the reset command without any pre-configured scope.",

plugins/store/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async fn create_store<R: Runtime>(
116116
}
117117

118118
#[tauri::command]
119-
async fn new_or_existing<R: Runtime>(
119+
async fn load<R: Runtime>(
120120
app: AppHandle<R>,
121121
store_state: State<'_, StoreState>,
122122
path: PathBuf,
@@ -132,7 +132,7 @@ async fn new_or_existing<R: Runtime>(
132132
serialize_fn_name,
133133
deserialize_fn_name,
134134
)?;
135-
let (_, rid) = builder.new_or_existing_inner()?;
135+
let (_, rid) = builder.load_inner()?;
136136
Ok(rid)
137137
}
138138

@@ -229,9 +229,9 @@ async fn length<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<usize>
229229
}
230230

231231
#[tauri::command]
232-
async fn load<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
232+
async fn reload<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
233233
let store = app.resources_table().get::<Store<R>>(rid)?;
234-
store.load()
234+
store.reload()
235235
}
236236

237237
#[tauri::command]
@@ -290,7 +290,7 @@ pub trait StoreExt<R: Runtime> {
290290
/// tauri::Builder::default()
291291
/// .plugin(tauri_plugin_store::Builder::default().build())
292292
/// .setup(|app| {
293-
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).new_or_existing()?;
293+
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).load()?;
294294
/// Ok(())
295295
/// });
296296
/// ```
@@ -326,7 +326,7 @@ pub trait StoreExt<R: Runtime> {
326326

327327
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
328328
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
329-
StoreBuilder::new(self.app_handle(), path).new_or_existing()
329+
StoreBuilder::new(self.app_handle(), path).load()
330330
}
331331

332332
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
@@ -447,15 +447,15 @@ impl Builder {
447447
/// tauri::Builder::default()
448448
/// .plugin(tauri_plugin_store::Builder::default().build())
449449
/// .setup(|app| {
450-
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").new_or_existing()?;
450+
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").load()?;
451451
/// Ok(())
452452
/// });
453453
/// ```
454454
pub fn build<R: Runtime>(self) -> TauriPlugin<R> {
455455
plugin::Builder::new("store")
456456
.invoke_handler(tauri::generate_handler![
457457
create_store,
458-
new_or_existing,
458+
load,
459459
get_store,
460460
close_store,
461461
set,
@@ -468,7 +468,7 @@ impl Builder {
468468
values,
469469
length,
470470
entries,
471-
load,
471+
reload,
472472
save,
473473
])
474474
.setup(move |app_handle, _api| {

0 commit comments

Comments
 (0)