npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuex-persistfile

v0.1.4

Published

Persist Vuex state in the filesystem for Electron

Downloads

18

Readme

Vuex Persist File

A Vuex plugin that automatically loads and persists the state to the filesystem. It's built to work in a Node.js environment, but it's especially useful with tools such as Electron or NW.js.

Installation

npm install --save vuex-persistfile

or

yarn add vuex-persistfile

Usage

First off, import it.

import VuexPersist from 'vuex-persistfile'

Initialize the plugin by passing the only required option: path, which should point to the directory where you want the store to be saved.

const persist = new VuexPersist({
  path: 'some/directory'
})

Finally register it as a Vuex plugin.

const store = new Vuex.store({
  // state, mutations, etc...
  plugins: [persist.subscribe()]
})

Now you're all setup! Vuex state will be saved and hydrated automatically.

Options

path

The directory where the file will be saved and read from. In Electron it makes sense for it to be something like app.getPath('userData'), which points to the platform specific application data directory.

file

The file where to save the state in JSON form. It's by default set to store.json, so you'll rarely need to set it manually, but you have that option. Basically, the final path will be path + file.

reducer

A function that returns an object literal with the state properties that you want to persist. In most cases you won't need the complete state persisted. Some properties may be single use or just unimportant to persist, so the reducer option trims the state tree.

const persist = new VuexPersist({
  path: 'some/directory',
  reducer: (state) => {
    return {
      aProp: state.aProp,
      bProp: state.bProp
    }
  }
})

mutations

A whitelist of mutations you want to persist. Any other mutations that aren't preset in that list will be discarded and won't trigger a state save.

const persist = new VuexPersist({
  path: 'some/directory',
  mutations: ['addUser', 'updateUser']
})

Custom Driver

Not sure why you'll need to override the default filesystem driver, but if you feel like it, you can easily create your own. Just create a class that exposes a write and read method. Something like the following:

export default class MyAwesomeDriver {
  write(path, data) {
    // write it somewhere
  }
  
  read(path) {
    // read it from somewhere
  } 
}

Then initialize it and pass it as an option to the plugin:

const MyAwesomeDriver = MyAwesomeDriver()

const persist = new VuexPersist({
  path: 'some/directory',
  driver: MyAwesomeDriver
})