Skip to content

How to use this project with IoC ? #2

Answered by daltonmenezes
michael-dm asked this question in Q&A
Discussion options

You must be logged in to vote

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 the ipcMain.handle.[handler] or ipcRenderer.handle.[handler] like:

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 getPing handler if you would like to and return the expected contract defined by the dumb handler or passing as any

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by michael-dm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1 on November 29, 2022 16:26.