mercredi 3 juillet 2019

Design pattern to solve event mess in Electron apps with ipcMain and ipcRenderer

Because Electron has two processes our javasript code is not global, so I find myself sending and receiving a lot of events (with a lot of different names) to do something that we usually do with just a callback in the same method.
This is even worse if we need to share some global var (for example global constants).

My current approach is try to manage the connection between Main and Renderer as a websocket, but it does not feel so good and maybe I'm doing it wrong.
I'm managing the windows (Renderer process) as a View from MVC.
Maybe I should use the main process only to init the main window and then do everything (database, external api calls, etc) from our window (Renderer)? (that is, MVC all in Renderer process, and do almost nothing in Main process?)

What is a good design pattern to solve this two processes thing from Electron?

Aucun commentaire:

Enregistrer un commentaire