Skip to content

Commit

Permalink
Everything compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile committed Aug 8, 2022
1 parent b0c0126 commit 0bb8cd5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
49 changes: 25 additions & 24 deletions examples/counter_functional/src/main.rs
Original file line number Diff line number Diff line change
@@ -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! {
<>
<p @disabled={false}> {"current count: "} {*state} </p>
<button onclick={incr_counter}> {"+"} </button>
<button onclick={decr_counter}> {"-"} </button>
</>
}
}
// #[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! {
// <>
// <p @disabled={false}> {"current count: "} {*state} </p>
// <button onclick={incr_counter}> {"+"} </button>
// <button onclick={decr_counter}> {"-"} </button>
// </>
// }
// }

fn main() {
yew::Renderer::<App>::new().render();
let _d = html! {
<div class={format!("fail{}", "")}></div>
};
}
2 changes: 1 addition & 1 deletion packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 2 additions & 4 deletions packages/yew-macro/src/props/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ pub struct Prop {
impl Parse for Prop {
fn parse(input: ParseStream) -> syn::Result<Self> {
let at = input.parse::<Token![@]>().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
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/btag/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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");
Expand Down

0 comments on commit 0bb8cd5

Please sign in to comment.