8000 Save `libraryData` using `@solid-primitives/filesystem` · Issue #7 · adithyasource/clear · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Save libraryData using @solid-primitives/filesystem #7
Open
@jer3m01

Description

@jer3m01

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

No one assigned

    Labels

    refactorsuggestion to improve (refactor) the code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0