Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-store-vuex-sync

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-store-vuex-sync

auto sync electron-store and vuex

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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的注入请放在最顶上

FAQs

Package last updated on 09 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc