-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Feature: on_mount() component lifecycle method #572
Comments
@hgzimmerman Yeah, this proposal sounds great! Feel free to get started and ping on gitter or here if you have any questions |
I can open a PR whenever, I'd just like to check some assumptions first: If I understand correctly, the component lifecycle is as follows:
I've stuck the ComponentState::Created(state.create().update().mounted()) The way a component is mounted appears to rely on If the above assumption is correct, then I think I stuck the |
Yeah sounds right to me! |
583: Add default mounted() method to Component trait r=jstarry a=hgzimmerman Fixes #572 I made the choice to have `on_mount()` not return a `ShouldRender` bool, because I don't think there is a situation where altering parts of a component state relevant to the `view()` should ever take place in `on_mount()` instead of `create()`. Let me know your thoughts, because its an easy enough change to make. Co-authored-by: Henry Zimmerman <zimhen7@gmail.com>
Description
**I'm submitting a Feature Request
I want to have one of my components send a request to an agent as soon as it is created and have its reply message assist in setting up the component.
What I currently do is send the message off in the
create()
method and hope that the component mounts and is ready to receive the response from the agent in time. In practice, it always does, but it doesn't seem correct to send off requests before the newly-created component is mounted and ready to handle replies.I propose that an overridable
on_mount()
method be added to the Component trait. By default, it would not contain any code, and would be called after the component is attached to the vdom(?).I admit that I'm coming from a point of ignorance and I accept that some queuing mechanism may already exist to avoid reply messages being dropped when their target component isn't ready. If that is the case, I'll happily close this issue and consider the sending messages to agents in
create()
acceptable.The text was updated successfully, but these errors were encountered: