Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save libraryData using @solid-primitives/filesystem #7

Open
jer3m01 opened this issue May 8, 2024 · 0 comments
Open

Save libraryData using @solid-primitives/filesystem #7

jer3m01 opened this issue May 8, 2024 · 0 comments
Labels
refactor suggestion to improve (refactor) the code

Comments

@jer3m01
Copy link
Contributor

jer3m01 commented May 8, 2024

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

@adithyasource adithyasource added the refactor suggestion to improve (refactor) the code label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor suggestion to improve (refactor) the code
Projects
None yet
Development

No branches or pull requests

2 participants