GithubHelp home page GithubHelp logo

tauri-pinia's Introduction

tauri-pinia

This is a small utility that brings persistance to pinia for tauri apps

Installation is pretty simple

const app = createApp(YourApp)
app.use(await tauriPinia())
app.mount('#app')

It requires await during initialisation however because the module will do a first read from fs before initialisation.

Some configuration is available (given as argument to tauriPinia()):

  • singleFile: If we do use single file for storage or one file per store
  • storeFilename: (when singleFile = false) A store name to file name conversion, should you need it (e.g. {'myStore': 'storageFileForMyStore.json'}) it is not mandatory
  • filename: (when singleFile = true) The name of the file to save in
  • logger: A function, the same type as console.log for those who want more info what's happening
  • excludeStore: List of stores to exclude completely from persisting

Non-persistant attributes

tauri-pinia now allows for non persistant attributes. In order to do it, a new property has been added in StoreConfig: ignoreProps.

In order to use it, simply do the following:

import { acceptHMRUpdate, defineStore } from 'pinia'

export const useCredentialStore = defineStore('credential', () => {
  const username = ref<string>()
  const password = ref<string>()
  const userId = ref<string>()

  const withDefault = ref<string>('default_value')
  const ignored = ref<number>(0)

  return { username, password, jiraUrl, userId, withDefault, ignored }
}, {
  ignoreProps: ['ignored'],
})

if (import.meta.hot)
  import.meta.hot.accept(acceptHMRUpdate(useCredentialStore as any, import.meta.hot))

In this example, the property ignored won't be written to disk nor loaded from disk.

tauri-pinia's People

Contributors

charlesgael avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

skopz356 bitsy-ai

tauri-pinia's Issues

Feature request: allow non-persistent attributes or/and stores

First, thanks for this library, it's a very nice and easy to use alternative to more traditional options! ๐Ÿ‘

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

I'd like to have a way to mark either a store or an attribute of a state non-persistent so that it would always be based on the provided initial value. Currently for example something like appInitReady: false which gets toggled to true in init() action is currently stored as true on disk and the logic needs to be rewritten in order to work w/ tauri-pinia. There are many cases where empty / predefined initial values would be useful.

Initial ideas:

  • allow marking non-persistent attributes in config (something in the lines of await tauriPinia({ excludedAttrs: ['debug', 'isInited', 'createdAt'] }))
  • offer an api to mark store not to be persisted (in config or maybe easier via a state attribute like dontPersist: true)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.