How to use this project with IoC ? #2
-
Hello, this project is very promising, congrats ✨ I'm wondering how to use it in a project that follows the Instead of this structure : export const getPingIpcSlice = createIpcSlice({
main: {
async getPing(_, data: 'ping') {
return `from renderer: ${data} on main process`
},
},
}) I have something like : export class MyController {
constructor(private myService: MyService) {}
async getPing(_, data: 'ping') {
const res = await this.myService.doSomething(data)
return `from renderer: ${res} on main process`
}
} But with this I don't see how I can import these methods into a shared file that uses |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If I understand correctly, handlers in the If I'm correct, what would you recommend for handlers that return complex data ? returning a dummy object like so ? import { createInterprocess } from 'interprocess'
export const { ipcMain, ipcRenderer, exposeApiToGlobalWindow } = createInterprocess({
main: {
// method will be really handled by main
async setMaximize(_, data: { maximize: boolean }) {
return { isMaximized: true }
}
},
renderer: {}
}) |
Beta Was this translation helpful? Give feedback.
-
Hi @michael-dm , thanks. 💜 That's right, you can make the handlers dumb in the ipcMain.handle.getPing(async (_, { getPing, data }) => {
// call the registered handler if needed (lazy)
const response = await getPing(_, data)
await ipcMain.invoke.getPong(mainWindow, 'pong')
ipcMain.remove.getPing()
return 'The getPong ipc was removed'
}) You can handle complex work without calling the destructured |
Beta Was this translation helpful? Give feedback.
Hi @michael-dm , thanks. 💜
That's right, you can make the handlers dumb in the
createInterprocess
definition just to make the contract as you need, and you should pass a callback to theipcMain.handle.[handler]
oripcRenderer.handle.[handler]
like:You can handle complex work without calling the destructured
getPing
handler if you would like to and return the expected contract defined by the dumb handler or passingas any