Skip to content

jean-moreno/vuex-electron

 
 

Repository files navigation

Vuex Electron

Travis Code Climate Code Climate Code Style Prettier Made With Love

The easiest way to share your Vuex Store between all processes (including main).

Fork

This fork contains the following modifications:

  • properly initialize state when creating a new renderer process and when not using persistent state
  • allow renderer processes to commit mutations

Features

⭐ Persisted state
⭐ Shared mutations

Requirements

Installation

Installation of the Vuex Electron easy as 1-2-3.

  1. Install package with using of yarn or npm:

    yarn install vuex-electron
    

    or

    npm install vuex-electron
    
  2. Include plugins in your Vuex store::

    import Vue from "vue"
    import Vuex from "vuex"
    
    import { createPersistedState, createSharedMutations } from "vuex-electron"
    
    Vue.use(Vuex)
    
    export default new Vuex.Store({
      // ...
      plugins: [
        createPersistedState(),
        createSharedMutations()
      ],
      // ...
    })
  3. In case if you enabled createSharedMutations() plugin you need to create an instance of store in the main process. To do it just add this line into your main process (for example src/main.js):

    import './path/to/your/store'
  4. Well done you did it! The last step is to add the star to this repo 😄

Usage example: Vuex Electron Example

Options

Available options for createPersistedState()

createPersistedState({
  whitelist: ["whitelistedMutation", "anotherWhitelistedMutation"],

  // or

  whitelist: (mutation) => {
    return true
  },

  // or

  blacklist: ["ignoredMutation", "anotherIgnoredMutation"],

  // or

  blacklist: (mutation) => {
    return true
  }
})

Available options for createSharedMutations()

createSharedMutations({
  syncStateOnRendererCreation: true
})

syncStateOnRendererCreation: true will synchronize the main process's Vuex state with a renderer when it's created. Use it when createPersistedState() isn't used to make sure the states are synchronized (else you might end up with a different state between a renderer and the main process).

Warning

Vuex-electron uses ipc to share actions and mutations between processes, so the Vuex state is subject to the same limitations that ipc has, most notably the fact that data is serialized through JSON before being sent.

Authors

Andrew Emelianenko
IG: @truemelianenko

Modified by Jean Moreno for SyncSketch LLC

License

MIT License

About

Integration of Vuex and Electron

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%