Skip to content

Commit

Permalink
Update store plugin's docs to match the new rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Oct 21, 2024
1 parent e75ff29 commit b4eb468
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/content/docs/plugin/store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@ Install the store plugin to get started.
<TabItem label="JavaScript">

```typescript
import { createStore } from '@tauri-apps/plugin-store';
import { load } from '@tauri-apps/plugin-store';
// when using `"withGlobalTauri": true`, you may use
// const { createStore } = window.__TAURI__.store;
// const { load } = window.__TAURI__.store;

// create a new store or load the existing one
const store = await createStore('store.bin', {
// we can save automatically after each store modification
autoSave: true,
});
const store = await load('store.bin');

// Set a value.
await store.set('some-key', { value: 5 });
Expand All @@ -111,7 +108,7 @@ pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = app.handle().store_builder("store.bin").build();
let store = app.store("store.json")?;

// Note that values must be serde_json::Value instances,
// otherwise, they will not be compatible with the JavaScript bindings.
Expand All @@ -121,11 +118,6 @@ pub fn run() {
let value = store.get("some-key").expect("Failed to get value from store");
println!("{}", value); // {"value":5}

// You can manually save the store after making changes.
// Otherwise, it will save upon graceful exit as described above.
store.save()?;


Ok(())
})
.run(tauri::generate_context!())
Expand All @@ -136,6 +128,32 @@ pub fn run() {
</TabItem>
</Tabs>

## Migrating from v1 and v2 beta/rc


<Tabs>
<TabItem label="JavaScript">

```diff
- import { Store } from '@tauri-apps/plugin-store';
+ import { LazyStore } from '@tauri-apps/plugin-store';
```

</TabItem>
<TabItem label="Rust">

```diff
- with_store(app.handle().clone(), stores, path, |store| {
- store.insert("some-key".to_string(), json!({ "value": 5 }))?;
- Ok(())
- });
+ let store = app.store(path)?;
+ store.set("some-key".to_string(), json!({ "value": 5 }));
```

</TabItem>
</Tabs>

## Permissions

By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your `capabilities` configuration to enable these.
Expand Down

0 comments on commit b4eb468

Please sign in to comment.