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

Question: How to Fire command on Sub-component Initialization #265

Open
Zalarian opened this issue Jul 31, 2022 · 4 comments
Open

Question: How to Fire command on Sub-component Initialization #265

Zalarian opened this issue Jul 31, 2022 · 4 comments

Comments

@Zalarian
Copy link

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.

@mflibby
Copy link

mflibby commented Aug 19, 2022

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.

@Martin521
Copy link

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.

@Zalarian
Copy link
Author

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

@Martin521
Copy link

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

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

No branches or pull requests

3 participants