The easiest way to share your Vuex Store between all processes (including main).
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
⭐ Persisted state
⭐ Shared mutations
Installation of the Vuex Electron easy as 1-2-3.
-
Install package with using of yarn or npm:
yarn install vuex-electron
or
npm install vuex-electron
-
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() ], // ... })
-
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 examplesrc/main.js
):import './path/to/your/store'
-
Well done you did it! The last step is to add the star to this repo 😄
Usage example: Vuex Electron Example
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).
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.
Andrew Emelianenko
IG: @truemelianenko
Modified by Jean Moreno for SyncSketch LLC