Bolero icon indicating copy to clipboard operation
Bolero copied to clipboard

Question: How to Fire command on Sub-component Initialization

Open Zalarian opened this issue 1 year ago • 4 comments

Title is pretty descriptive.

I am using Elmish and am following the parent-child approach. When I initialize a specific sub-component I want that make a remoting request to populate the front end with data from the backend. I haven't been able to work out how to handle a command on init.

Zalarian avatar Jul 31 '22 21:07 Zalarian

Also interested in this functionality: Elm generally just requires the definition of the "init" function to reflect the return of a command, but building the same functionality here seems to be much more involved, if it is at all possible.

mflibby avatar Aug 19 '22 23:08 mflibby

You can have init functions in your sub-components that perform local initialization and return commands for async initialization (e.g. with network requests). The init function of your main module calls the sub-component init functions to batch their commands into its own command for return. This works pretty well for me.

Martin521 avatar Aug 20 '22 07:08 Martin521

Does this work with the built-in router and PageModel approach?

Zalarian avatar Aug 25 '22 00:08 Zalarian

I haven't tried that (I do SPA), but I don't see why it would not work.

Martin521 avatar Aug 25 '22 07:08 Martin521