Bolero
Bolero copied to clipboard
Question: How to Fire command on Sub-component Initialization
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.
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.
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.
Does this work with the built-in router and PageModel approach?
I haven't tried that (I do SPA), but I don't see why it would not work.