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

electron-store-vuex-sync

v1.1.0

Published

auto sync electron-store and vuex

Downloads

1

Readme

Electron-store-vuex-sync

自动同步electron-storevuex

使用方法

在background.js中(node进程)

const { ipcMain } = require('electron')
const Store = require('electron-store');
const { injectStore } = require('electron-store-vuex-sync')
const store = new Store();

injectStore(ipcMain, store)

在创建vuex的地方

import Vuex from 'vuex'
import { getVuexStoreConfig } from 'electron-store-vuex-sync'
import { ipcRenderer } from 'electron'

const store = new Vuex.Store(getVuexStoreConfig(ipcRenderer))
return store

如果需要可以update

如果需要vuex可以同步回store

import Vuex from 'vuex'
import { getVuexStoreConfig } from 'electron-store-vuex-sync'
import { ipcRenderer } from 'electron'

const schema = {
    a: {
        type: 'array'
    }
}

const store = new Vuex.Store(getVuexStoreConfig(ipcRenderer, schema))
return store

这样,会根据你schema的key,自动添加mutation,名字类似于set:key名

初始化的vuex state和store同步

默认情况下,state根据schema推导,但是可以通过传入第四个参数defaultStore,让state中每个属性就为defaultStore对应的值

默认同步会在加载成功后通过对应事件同步

import Vuex from 'vuex'
import { getVuexStoreConfig } from 'electron-store-vuex-sync'
import { ipcRenderer } from 'electron'
import store from '../store' // 导出的electron store

const schema = {
    a: {
        type: 'array'
    }
}

const store = new Vuex.Store(getVuexStoreConfig(ipcRenderer, schema, null, store))
return store

这样,会根据你schema的key,自动添加mutation,名字类似于set:key名

参数

injectStore

  • ipcMain electronipcMain用来注入监听事件
  • store electron-store创建的store
  • [storeName] 当前这个store的名字需要不同页面同步不同store的时候需要,可选

返回传入的store

getVuexStoreConfig

  • ipcRenderer electronipcRenderer用来注入监听事件
  • [schema] electron-storeschema可以根据这个自动初始化,省去手动的问题
  • [storeName] 当前这个store的名字需要不同页面同步不同store的时候需要,可选

其他的事

  1. 如果使用schema来初始化的话,vuexmutationset:schema的key

  2. 只会生成对应的vuex配置,像是state,action这些你可以通过解构等方法把自己的方法注入进去

  3. 因为electron-store默认名字为config,所以vuex用来初始化和同步的事件前缀也默认为config:

  4. background的注入请放在最顶上