-
We could expose the underlying electron-store instance so you can change the persisted state from outside of Vuex. Maybe an API like this would work: import { store } from 'vuex-electron-store'
// See https://github.com/sindresorhus/electron-store#instance
store.set('unicorn', '🦄')
const unicorn = store.get('unicorn')
console.log(unicorn) // => 🦄 This would be useful if you want to access the persisted state in the main process. Changing the data this way might be a problem because Vuex Plugins can't change the state directly. We would have to watch for changes and then commit a mutation which would synchronize the data to the state manually. That means the user would have to add a mutation in addition to importing the plugin: new Vuex.Store({
mutations: {
...PersistedState.syncMutation,
// ...
},
plugins: [
PersistedState.create()
]
}) I will have to research and test if this could work reliably. Another option would be to add support for shared mutations. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I implemented this in the form of Enable PersistedState.create({
ipc: true
}) Then in the Electron main process: import PersistedState from 'vuex-electron-store'
const store = PersistedState.getStoreFromRenderer()
// Commit a mutation
store.commit(type, payload)
// Dispatch an action
store.dispatch(action, payload)
// Get the current Vuex State
const state = await store.getState() This way you can change the state with mutations and also dispatch actions to do other things. |
Beta Was this translation helpful? Give feedback.
I implemented this in the form of
ipc
mode in v1.3.0:Enable
ipc
mode:Then in the Electron main process:
This way you can change the state with mutations and also dispatch actions to do other things.