From fbf88e3b2e4f2311863cbae2c71865274cc5a112 Mon Sep 17 00:00:00 2001 From: Henry Zimmerman Date: Thu, 9 Jan 2020 18:18:27 -0500 Subject: [PATCH] Fix breaking changes in Yew (#217) * initial work - held up by broken generic components * fix guide example --- examples/guide/src/guide.rs | 6 +++--- examples/guide/src/markdown_window.rs | 2 +- examples/guide/src/page.rs | 2 +- examples/minimal/src/main.rs | 6 +++--- examples/router_component/src/a_component.rs | 13 ++++++------- examples/router_component/src/b_component.rs | 2 +- examples/router_component/src/c_component.rs | 2 +- src/components/mod.rs | 4 ++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/examples/guide/src/guide.rs b/examples/guide/src/guide.rs index f73d791..7d30433 100644 --- a/examples/guide/src/guide.rs +++ b/examples/guide/src/guide.rs @@ -11,7 +11,7 @@ pub struct Guide { props: GuideProps, } -#[derive(Properties)] +#[derive(Properties, Clone)] pub struct GuideProps { children: ChildrenWithProps, } @@ -100,13 +100,13 @@ fn render_page_list_item(props: PageProps, route: &Route) -> Html { log::debug!("Found an active"); return html! {
  • - route=props.page_url.clone()> {&props.title} + route=props.page_url.clone()> {&props.title} >
  • }; } else { return html! {
  • - route=props.page_url.clone()> {&props.title} + route=props.page_url.clone()> {&props.title} >
  • }; } diff --git a/examples/guide/src/markdown_window.rs b/examples/guide/src/markdown_window.rs index 41ac6a9..f2960ff 100644 --- a/examples/guide/src/markdown_window.rs +++ b/examples/guide/src/markdown_window.rs @@ -17,7 +17,7 @@ pub struct MarkdownWindow { link: ComponentLink, } -#[derive(Properties, Debug)] +#[derive(Properties, Debug, Clone)] pub struct MdProps { pub uri: Option, } diff --git a/examples/guide/src/page.rs b/examples/guide/src/page.rs index 9b59fd4..43e8b73 100644 --- a/examples/guide/src/page.rs +++ b/examples/guide/src/page.rs @@ -2,7 +2,7 @@ use yew::{prelude::*, virtual_dom::VNode}; pub struct Page; -#[derive(Properties)] +#[derive(Properties, Clone)] pub struct PageProps { #[props(required)] pub uri: String, diff --git a/examples/minimal/src/main.rs b/examples/minimal/src/main.rs index ca398dc..d0c24ad 100644 --- a/examples/minimal/src/main.rs +++ b/examples/minimal/src/main.rs @@ -93,10 +93,10 @@ impl Component for Model {
    { match AppRoute::switch(self.route.clone()) { - Some(AppRoute::A(thing)) => html!{thing}, + Some(AppRoute::A(thing)) => VNode::from(thing.as_str()), Some(AppRoute::B{anything, number}) => html!{
    {anything} {number}
    }, - Some(AppRoute::C) => html!{"C"}, - None => html!{"404"} + Some(AppRoute::C) => VNode::from("C"), + None => VNode::from("404") } }
    diff --git a/examples/router_component/src/a_component.rs b/examples/router_component/src/a_component.rs index 37e4f0a..ef72dfb 100644 --- a/examples/router_component/src/a_component.rs +++ b/examples/router_component/src/a_component.rs @@ -6,7 +6,7 @@ pub struct AModel { props: Props, } -#[derive(PartialEq, Properties)] +#[derive(Clone, PartialEq, Properties)] pub struct Props { #[props(required)] pub route: Option, @@ -36,12 +36,11 @@ impl Component for AModel {
    { "I am the A component"}
    - route=AppRoute::A(AllowMissing(Some(ARoute)))> - {"Go to a/c"} - - // - // {"Go to a/d (route does not exist)"} - // + + route=AppRoute::A(AllowMissing(Some(ARoute))) + /> +// {"Go to a/c"} +// >
    { diff --git a/examples/router_component/src/b_component.rs b/examples/router_component/src/b_component.rs index 1d95f1f..937326e 100644 --- a/examples/router_component/src/b_component.rs +++ b/examples/router_component/src/b_component.rs @@ -10,7 +10,7 @@ pub struct BModel { update_subpath: Callback, } -#[derive(PartialEq, Properties)] +#[derive(Clone, PartialEq, Properties)] pub struct Props { #[props(required)] pub number: Option, diff --git a/examples/router_component/src/c_component.rs b/examples/router_component/src/c_component.rs index 12c37e7..c88f1d9 100644 --- a/examples/router_component/src/c_component.rs +++ b/examples/router_component/src/c_component.rs @@ -2,7 +2,7 @@ use yew::{prelude::*, virtual_dom::VNode, Properties}; pub struct CModel; -#[derive(PartialEq, Properties)] +#[derive(Clone, PartialEq, Properties)] pub struct Props {} pub enum Msg {} diff --git a/src/components/mod.rs b/src/components/mod.rs index 136d992..d846ef2 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -15,10 +15,10 @@ use crate::Switch; // TODO This should also be PartialEq and Clone. Its blocked on Children not supporting that. // TODO This should no longer take link & String, and instead take a route: SW implementing Switch /// Properties for `RouterButton` and `RouterLink`. -#[derive(Properties, Default, Debug)] +#[derive(Properties, Clone, Default, Debug)] pub struct Props where - SW: Switch, + SW: Switch + Clone, { /// The Switched item representing the route. #[props(required)]