Skip to content

How to use this project with IoC ? #1

Closed

Description

@michael-dm

Hello,

this project is very promising, congrats ✨

I'm wondering how to use it in a project that follows the Inversion of Control principle (through dependency injection).

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 combineIpcs.
What do you think ?

Activity

  1. michael-dm commented on Nov 29, 2022

    @michael-dm
    Author

    If I understand correctly, handlers in the shared folder can be "dummy" handlers, to ensure typings are correct on both end, and I can then implement real logic using ipcMain.handle.

    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: {}
    })
  2. Repository owner locked and limited conversation to collaborators on Nov 29, 2022
  3. converted this issue into a discussion #2 on Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions