Reputation: 921
I am developing an electron application and I have rather an architectural problem in general.
Whenever I have something that needs to be done in the Main process, I do it directly in the main.js file, I believe this is wrong because I will end up with a very long monolithic file. !
Now I am adding more classes, and some of those classes should listen to an event. Let me give an example:
In my application, I should have a profile instance. This profile should be updated when the user attempt to login from the Renderer process.
Now my problems is where to create the instance of profile, and how to automatically listen to LOAD_PROFILE event for example? And do I really need to create a profile instance in Main, the only parts that I need to do in main is load and store the profile in desk. All other interaction with profile is done in Renderer.
I am new to node.js and Electron so it's fundamental architecture is a bit confusing for me.
Upvotes: 1
Views: 710
Reputation: 921
Well, just in case someone else had the same question.
What I did is just writing the listener code in a new file and imported the file into main.js. Since the code is evaluated once at import, the listeners are registered.
"Be aware that multiple imports in some cases can lead to the code executed several times." Please look here for reference: https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/
Upvotes: 1