From 0bb8cd5cf3e95f8b01b7aa7725a08f5ac954e57c Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Mon, 8 Aug 2022 22:52:44 +0500 Subject: [PATCH] Everything compiles --- examples/counter_functional/src/main.rs | 49 ++++++++++--------- .../yew-macro/src/html_tree/html_element.rs | 2 +- packages/yew-macro/src/props/prop.rs | 6 +-- .../yew/src/dom_bundle/btag/attributes.rs | 4 +- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/examples/counter_functional/src/main.rs b/examples/counter_functional/src/main.rs index 1fb79081b66..926d5fc3a99 100644 --- a/examples/counter_functional/src/main.rs +++ b/examples/counter_functional/src/main.rs @@ -1,28 +1,29 @@ use yew::prelude::*; - -#[function_component] -fn App() -> Html { - let state = use_state(|| 0); - - let incr_counter = { - let state = state.clone(); - Callback::from(move |_| state.set(*state + 1)) - }; - - let decr_counter = { - let state = state.clone(); - Callback::from(move |_| state.set(*state - 1)) - }; - - html! { - <> -

{"current count: "} {*state}

- - - - } -} +// #[function_component] +// fn App() -> Html { +// let state = use_state(|| 0); +// +// let incr_counter = { +// let state = state.clone(); +// Callback::from(move |_| state.set(*state + 1)) +// }; +// +// let decr_counter = { +// let state = state.clone(); +// Callback::from(move |_| state.set(*state - 1)) +// }; +// +// html! { +// <> +//

{"current count: "} {*state}

+// +// +// +// } +// } fn main() { - yew::Renderer::::new().render(); + let _d = html! { +
+ }; } diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index b2c1b640162..8afa2e0ab37 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -259,7 +259,7 @@ impl ToTokens for HtmlElement { quote! { ::yew::virtual_dom::ApplyAttributeAs::Property } }; let value = wrap_attr_value(v); - quote! { (#value, #apply_as) } + quote! { ::std::option::Option::map(#value, |it| (it, ::yew::virtual_dom::ApplyAttributeAs::Property)) } }); quote! { ::yew::virtual_dom::Attributes::Dynamic{ diff --git a/packages/yew-macro/src/props/prop.rs b/packages/yew-macro/src/props/prop.rs index 820eb2963fd..21adb48b75d 100644 --- a/packages/yew-macro/src/props/prop.rs +++ b/packages/yew-macro/src/props/prop.rs @@ -22,13 +22,11 @@ pub struct Prop { impl Parse for Prop { fn parse(input: ParseStream) -> syn::Result { let at = input.parse::().map(|_| true).unwrap_or(false); - let prop = if input.peek(Brace) { + if input.peek(Brace) { Self::parse_shorthand_prop_assignment(input, at) } else { Self::parse_prop_assignment(input, at) - }; - eprintln!("prop => {:?}; at?: {}", prop.as_ref().map(|prop| format!("label: {}, value: {:?}", prop.label.to_string(), prop.value)), at); - prop + } } } diff --git a/packages/yew/src/dom_bundle/btag/attributes.rs b/packages/yew/src/dom_bundle/btag/attributes.rs index c10402ce41f..7e7ab726857 100644 --- a/packages/yew/src/dom_bundle/btag/attributes.rs +++ b/packages/yew/src/dom_bundle/btag/attributes.rs @@ -288,7 +288,7 @@ mod tests { #[test] fn properties_are_set() { - let attrs = Attributes::Static(&[["href", "https://example.com/"], ["alt", "somewhere"]]); + let attrs = Attributes::Static(&[("href", "https://example.com/", ApplyAttributeAs::Property), ("alt", "somewhere", ApplyAttributeAs::Property)]); let (element, btree) = create_element(); attrs.apply(&btree, &element); assert_eq!( @@ -311,7 +311,7 @@ mod tests { #[test] fn class_id_are_attrs() { - let attrs = Attributes::Static(&[["id", "foo"], ["class", "thing"]]); + let attrs = Attributes::Static(&[("id", "foo", ApplyAttributeAs::Attribute), ("class", "thing", ApplyAttributeAs::Attribute)]); let (element, btree) = create_element(); attrs.apply(&btree, &element); assert_eq!(element.get_attribute("id").unwrap(), "foo");