yew icon indicating copy to clipboard operation
yew copied to clipboard

Easy link holding of child component

Open Turakar opened this issue 5 years ago • 1 comments

Is your feature request related to a problem? Please describe. Suppose I have components A and B, where A is composed of B. Now A wants to send some messages to B. This would be easy, if A has a direct reference to B's link.

Describe the solution you'd like It would be useful, if we can pass a reference during creation of the component using html!, e.g.

html! {
    <ChildComponent link_ref=self.my_child />
}

Where self.my_child would be of an appropriate type, probably something like Option<ComponentLink<ChildComponent>>.

It was also considered to use ref directly for this, s.t. the link can be taken from the NodeRef directly. Whilst probably being quite intuitive (I actually search for the proposed functionality at first in in that struct), I think it would require runtime checks if the NodeRef actually points to a component or not. This might lead to less idiomatic code.

Describe alternatives you've considered See below for discussion. There is also a workaround.

Additional context See #1255 for initial discussion.

Turakar avatar May 22 '20 10:05 Turakar

Maybe link is a better name for the attribute.

Turakar avatar May 22 '20 11:05 Turakar