Trying to learn svelte and using dexie. Is there a better way to get data to the array from indexedDB?
My functions.js file
export const db = new Dexie("todos");
db.version(1).stores({
todo: "++id,note",
});
App.svelte
<script>
import { onMount } from "svelte";
import { db } from "./functions";
let newnote = "";
let addnote = (e) => {
db.todo.add({ note: newnote });
db.todo.toArray().then(items => {
todos = items;
});
};
$:todos = [];
let start = () => {
db.todo.toArray().then(items => {
todos = items;
});
};
onMount(() => {
start();
});
</script>
<main>
<h1 id="title">ToDo</h1>
<input type="text" id="newnote" bind:value={newnote} />
<input type="button" value="Add" on:click={addnote} />
<br>
{#each todos as todo}
{todo.note} <br>
{/each}
</main>
Btw, can you keep this code hidden in the app? If so, how? Or is that not necessary?