Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually invoke construction? #884

Open
idcmp opened this issue May 20, 2022 · 0 comments
Open

Manually invoke construction? #884

idcmp opened this issue May 20, 2022 · 0 comments

Comments

@idcmp
Copy link

idcmp commented May 20, 2022

Is your feature request related to a problem? Please describe.

I'm building a GTK app (using gotk4), using fx to create some of the Views and their backing models, and letting fx figure out hierarchy of dependencies for everything (view gets data from model, model gets data from database, database needs outstanding migrations run first, etc).

Unfortunately the Views (and other things) can only be safely (ie without panicing) constructed after the GTK subsystem has called the ConnectActivate callback of my gtk.Application. This callback is called when I call app.Run(...).

Describe the solution you'd like

Good question. I know I could spin up a separate fx.App inside my ConnectActivate callback, but I would lose all the rest of my wiring, and would have to figure out logging again, etc.. so I don't really want that.

Maybe I want to be able to be passed an invoker of sorts:

func NewApp(l *zap.Logger, invokerCalledOnActivate fx.Invoker) *gtk.Application {
  gtkApp := ...
  gtkApp.ConnectActivate(func() { 
    invokerCalledOnActivate.Invoke()
 }
return gtkApp
}

// NewUIDuringActivation only gets resolved by fx in the ConnectActivate callback above.
func NewUIDuringActivation(gtkApp *gtk.App, myTree *gtk.TreeView, myModel *gtk.TreeModel) InvokerCalledOnActivate { 
  invoker := &defaultInvoker {
   // member variables so that Invoke() eventually runs
   gtkApp.Attach(myTree)
  ...

 return invoker
}

..but that feels awkward.

Maybe I want to do all my initialization an OnStart ? That also seems suboptimal since my main goal is to create some of these dependencies during my ConnectActivate, not have them registered to be called later.

Maybe I wish executeInvoke was public and accessible through fx.App ?

Describe alternatives you've considered

See above.

Is this a breaking change?

No. This would be additive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant