You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now this is an oversimplified example. In my case it's not really a class, but an object that has functions added to it by a 3rd party library.
The problem is that when i dispatch the newCounter action from a renderer process the action is being intercepted and processed on the main process instead.
For this to happen, you currently send the dispatch type and payload using ipcRenderer.send(), which results in the payload losing the prototype chain and all functions as stated in the docs.
Proposed solution
I tried modifying the code of sharedMutations.js locally to simply sync mutations both ways instead of broadcasting them from main.
The result is that the prototypes and functions will be available within the process they were created, which i feel makes more sense than having all prototypes in the main process.
It seems to work well for my application, but I'm curious to whether or not you see an issue with this implementation.
I also removed the restriction of having to use actions in the renderer process, any mutations are now synced both ways.
rendererProcessLogic(){// Connect renderer to main processthis.connect()varmainMutating=false// Subscribe on changes from main process and apply themthis.onNotifyRenderers((event,{ type, payload })=>{mainMutating=truethis.store.commit(type,payload)mainMutating=false})// Subscribe on changes from Vuex storethis.store.subscribe(mutation=>{if(!mainMutating){const{ type, payload }=mutation// Forward changes to renderer processesthis.notifyMain({ type, payload })}})}mainProcessLogic(){constconnections={}// Save new connectionthis.onConnect(event=>{constwin=event.senderconstwinId=win.idconnections[winId]=win// Remove connection when window is closedwin.on('destroyed',()=>{deleteconnections[winId]})})// Subscribe on changes from renderer processesthis.onNotifyMain((event,{ type, payload })=>{constwin=event.senderconstwinId=win.iddeleteconnections[winId]this.store.commit(type,payload)connections[winId]=win})// Subscribe on changes from Vuex storethis.store.subscribe(mutation=>{if(connections){const{ type, payload }=mutation// Forward changes to renderer processesthis.notifyRenderers(connections,{ type, payload })}})}
I am willing to set up a PR if this is something you would like to use.
The text was updated successfully, but these errors were encountered:
The problem
I use this library in a project where i store a class in my state, kind of like this:
Now this is an oversimplified example. In my case it's not really a class, but an object that has functions added to it by a 3rd party library.
The problem is that when i dispatch the newCounter action from a renderer process the action is being intercepted and processed on the main process instead.
For this to happen, you currently send the dispatch type and payload using
ipcRenderer.send()
, which results in the payload losing the prototype chain and all functions as stated in the docs.Proposed solution
I tried modifying the code of sharedMutations.js locally to simply sync mutations both ways instead of broadcasting them from main.
The result is that the prototypes and functions will be available within the process they were created, which i feel makes more sense than having all prototypes in the main process.
It seems to work well for my application, but I'm curious to whether or not you see an issue with this implementation.
I also removed the restriction of having to use actions in the renderer process, any mutations are now synced both ways.
I am willing to set up a PR if this is something you would like to use.
The text was updated successfully, but these errors were encountered: