-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
refactorsuggestion to improve (refactor) the codesuggestion to improve (refactor) the code
Description
Instead of writing the data to system yourself, you can use @solid-primitives/filesystem to make a wrapper to tauri fs.
Once your libraryData is reactive (i.e. using a store from #6 in a context #5)
await writeTextFile(
{
path: "data.json",
contents: JSON.stringify(libraryData(), null, 4),
},
{
dir: BaseDirectory.AppData,
},
)
// becomes
const tfs = makeTauriFileSystem({dir: BaseDirectory.AppData});
const fs = createFileSystem(tfs);
// This will automatically write the file each time `libraryData` is changed
// Only write this once! This will run whenever the store is updated (from anywhere)
createEffect(() => fs.writeFile("data.json", JSON.stringify(unwrap(libraryData), null, 4)));Solid docs:
https://docs.solidjs.com/concepts/effects#effects
https://docs.solidjs.com/reference/basic-reactivity/create-effect
https://docs.solidjs.com/concepts/stores#extracting-raw-data-with-unwrap
Solid Primitives docs:
https://primitives.solidjs.community/package/filesystem
Metadata
Metadata
Assignees
Labels
refactorsuggestion to improve (refactor) the codesuggestion to improve (refactor) the code