So I have a React/electron application. Sometimes my main.js file sends some data over, via ipc. Up until now I had my React components send & wait for certain ipc events like so:
constructor(props) {
super(props);
ipcRenderer.send('sendTranslateRequest', "Bonjour mon amour");
ipcRenderer.on('receiveTranslateResponse', (evt, arg) => {
//... });
}
However, as I am using Redux now I found myself thinking a bit more about my apps architecture. Would it not be a good idea to create a separate file and put all my listeners into it, and whenever a listener is activated, to dispatch a Redux action. And likewise, to put all my ipcRenderer.sends into the respective Redux actions, so that my React Components are completely clear from all of that?
Would this be possible? And: Would this be a good idea?
I am wondering how I could create a file which has the ability to take all my listeners. So I would have a file like this:
ipcRenderer.on('receiveTranslateResponse', (evt, arg) => {
//dispatch actions then
});
ipcRenderer.on('receiveAnotherResponse', (evt, arg) => {
//dispatch actions then
});
What I don't understand is how I could include this file into my React application, how & where to execute it?