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

Add documentation for html_nested! macro #1428

Closed
1 task done
AgarwalPragy opened this issue Jul 20, 2020 · 0 comments · Fixed by #1530
Closed
1 task done

Add documentation for html_nested! macro #1428

AgarwalPragy opened this issue Jul 20, 2020 · 0 comments · Fixed by #1530

Comments

@AgarwalPragy
Copy link

This is about:

  • Undocumented code

Problem
#843 introduces a macro html_nested! that adds support for iterable nested children access.

There is no documentation on yew.rs for the the html_nested! macro


Macro is currently hidden from docs

#[doc(hidden)]
#[proc_macro_hack(support_nested)]
pub use yew_macro::html_nested;

because

We prohibit public items without documentation by setting a crate attribute, so when this was added it was #[doc(hidden)] to allow the crate to compile.


Example - faulty code using html!

use wasm_bindgen::prelude::*;
use yew::prelude::*;

pub struct Container {
    link: ComponentLink<Self>,
    props: Props,
}

enum Msg {}

#[derive(Properties, Clone, PartialEq)]
pub struct Props {
    #[prop_or_default]
    pub children: ChildrenWithProps<Container>,
}

impl Component for Container {
    type Message = ();
    type Properties = Props;

    fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
        Self { link, props }
    }

    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        false
    }

    fn change(&mut self, _props: Self::Properties) -> ShouldRender {
        false
    }

    fn view(&self) -> Html {
        html! {
            <Container>
                {
                for (1..10_i32).map(|item| {
                    html! {
                        <Container/>
                    }
                })
                }
            </Container>
        }
    }
}

above code gives the error:

error[E0277]: the trait bound `yew::virtual_dom::VChild<example::Container>: std::convert::From<yew::virtual_dom::VNode>` is not satisfied
  --> webui/src/example.rs:37:21
   |
37 |                   for (1..10_i32).map(|item| {
   |  _____________________^
38 | |                     html! {
39 | |                         <Container/>
40 | |                     }
41 | |                 })
   | |__________________^ the trait `std::convert::From<yew::virtual_dom::VNode>` is not implemented for `yew::virtual_dom::VChild<example::Container>`
   |
   = note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::VChild<example::Container>>` for `yew::virtual_dom::VNode`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

To fix, use html_nested!

    fn view(&self) -> Html {
        html! {
            <Container>
                {
                for (1..10_i32).map(|item| {
                    html_nested! {
                        <Container/>
                    }
                })
                }
            </Container>
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant