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

Adding children at runtime without html macro #88

Open
Tarnadas opened this issue Dec 9, 2019 · 0 comments
Open

Adding children at runtime without html macro #88

Tarnadas opened this issue Dec 9, 2019 · 0 comments

Comments

@Tarnadas
Copy link

Tarnadas commented Dec 9, 2019

Hey,

I'm trying to add children to a previously generated Node.
I need this, because I don't yet know how my DOM looks like at compile time.
I thought this would be possible with this code snippet, however it fails:

#[test]
fn test() {
    use typed_html::dom::{DOMTree, VNode};
    use typed_html::html;

    let mut root: DOMTree<String> = html!(<div></div>);
    let s = "Hello World";
    if let VNode::Element(root) = &mut root.vnode() {
        root.children.push(VNode::Text(s.as_ref()));
    };

    assert_eq!(root.to_string(), "<div>Hello World</div>");
}

thread 'test' panicked at 'assertion failed: (left == right)
left: "<div></div>",
right: "<div>Hello World</div>"', ui/main.rs:34:5

I get the same error for non-text nodes.

@Tarnadas Tarnadas changed the title Dynamically adding children Adding children at runtime without html macro Dec 9, 2019
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

1 participant