Easy link holding of child component

Open
#1,257 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
frontend

Research direction

Start with the html! component creation syntax described here and read the discussion in issue #1255, including the ComponentLink and NodeRef alternatives. Define the supported reference-passing behavior and verify that a parent can use it to send messages to its child component without relying on runtime NodeRef checks.

Written by the indexing model from the issue text.

Description

A-yew-macro feature-request

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.

Dominant language
Rust
Stars
32.8k
Forks
1.5k
Avg merge
5h 34m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from yewstack/yew

All issues in yewstack/yew

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.