mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-25 11:46:06 +02:00
Fix js get and close store
This commit is contained in:
@@ -7,15 +7,23 @@
|
||||
let key;
|
||||
let value;
|
||||
|
||||
const store = new LazyStore("cache.json");
|
||||
let store = new LazyStore("cache.json");
|
||||
let cache = {};
|
||||
|
||||
onMount(async () => {
|
||||
const values = await store.entries();
|
||||
for (const [key, value] of values) {
|
||||
cache[key] = value;
|
||||
async function refreshEntries() {
|
||||
try {
|
||||
const values = await store.entries();
|
||||
cache = {};
|
||||
for (const [key, value] of values) {
|
||||
cache[key] = value;
|
||||
}
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
cache = cache;
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await refreshEntries();
|
||||
});
|
||||
|
||||
async function write(key, value) {
|
||||
@@ -23,11 +31,33 @@
|
||||
await store.set(key, value);
|
||||
const v = await store.get(key);
|
||||
cache[key] = v;
|
||||
cache = cache;
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function reset() {
|
||||
try {
|
||||
await store.reset();
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
await refreshEntries();
|
||||
}
|
||||
|
||||
async function close() {
|
||||
try {
|
||||
await store.close();
|
||||
onMessage("Store is now closed, any new operations will now errors out");
|
||||
} catch (error) {
|
||||
onMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
function reopen() {
|
||||
store = new LazyStore("cache.json");
|
||||
onMessage("We made a new `LazyStore` instance, operations will now work");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col childre:grow gap-1">
|
||||
@@ -42,7 +72,12 @@
|
||||
<input class="grow input" bind:value />
|
||||
</div>
|
||||
|
||||
<button class="btn" on:click={() => write(key, value)}> Write </button>
|
||||
<div>
|
||||
<button class="btn" on:click={() => write(key, value)}>Write</button>
|
||||
<button class="btn" on:click={() => reset()}>Reset</button>
|
||||
<button class="btn" on:click={() => close()}>Close</button>
|
||||
<button class="btn" on:click={() => reopen()}>Re-open</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user