From 9438cc14bc8c2dd8781908a598684e723d45ec45 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 18 Feb 2022 23:17:33 -0500 Subject: [PATCH] fix: make listeners up to date --- packages/rsx/src/element.rs | 84 ++++++++++++++++++------------------- src/lib.rs | 2 +- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/packages/rsx/src/element.rs b/packages/rsx/src/element.rs index c612e9f1b..2c295d9a0 100644 --- a/packages/rsx/src/element.rs +++ b/packages/rsx/src/element.rs @@ -4,7 +4,7 @@ use proc_macro2::TokenStream as TokenStream2; use quote::{quote, ToTokens, TokenStreamExt}; use syn::{ parse::{Parse, ParseBuffer, ParseStream}, - Expr, ExprClosure, Ident, LitStr, Result, Token, + Expr, Ident, LitStr, Result, Token, }; // ======================================= @@ -81,24 +81,31 @@ impl Parse for Element { content.parse::()?; if name_str.starts_with("on") { - if content.fork().parse::().is_ok() { - // - attributes.push(ElementAttrNamed { - el_name: el_name.clone(), - attr: ElementAttr::EventClosure { - name, - closure: content.parse()?, - }, - }); - } else { - attributes.push(ElementAttrNamed { - el_name: el_name.clone(), - attr: ElementAttr::EventTokens { - name, - tokens: content.parse()?, - }, - }); - } + attributes.push(ElementAttrNamed { + el_name: el_name.clone(), + attr: ElementAttr::EventTokens { + name, + tokens: content.parse()?, + }, + }); + // if content.fork().parse::().is_ok() { + // // + // attributes.push(ElementAttrNamed { + // el_name: el_name.clone(), + // attr: ElementAttr::EventClosure { + // name, + // closure: content.parse()?, + // }, + // }); + // } else { + // attributes.push(ElementAttrNamed { + // el_name: el_name.clone(), + // attr: ElementAttr::EventTokens { + // name, + // tokens: content.parse()?, + // }, + // }); + // } } else { match name_str.as_str() { "key" => { @@ -203,28 +210,20 @@ impl ToTokens for Element { let name = &self.name; let children = &self.children; - // let listeners = &self.listeners; - let key = match &self.key { Some(ty) => quote! { Some(format_args_f!(#ty)) }, None => quote! { None }, }; - let listeners = self.attributes.iter().filter(|f| { - if let ElementAttr::EventTokens { .. } = f.attr { - true - } else { - false - } - }); + let listeners = self + .attributes + .iter() + .filter(|f| matches!(f.attr, ElementAttr::EventTokens { .. })); - let attr = self.attributes.iter().filter(|f| { - if let ElementAttr::EventTokens { .. } = f.attr { - false - } else { - true - } - }); + let attr = self + .attributes + .iter() + .filter(|f| !matches!(f.attr, ElementAttr::EventTokens { .. })); tokens.append_all(quote! { __cx.element( @@ -251,9 +250,8 @@ pub enum ElementAttr { /// "attribute": true, CustomAttrExpression { name: LitStr, value: Expr }, - /// onclick: move |_| {} - EventClosure { name: Ident, closure: ExprClosure }, - + // /// onclick: move |_| {} + // EventClosure { name: Ident, closure: ExprClosure }, /// onclick: {} EventTokens { name: Ident, tokens: Expr }, } @@ -288,11 +286,11 @@ impl ToTokens for ElementAttrNamed { __cx.attr( #name, format_args_f!(#value), None, false ) } } - ElementAttr::EventClosure { name, closure } => { - quote! { - dioxus_elements::on::#name(__cx, #closure) - } - } + // ElementAttr::EventClosure { name, closure } => { + // quote! { + // dioxus_elements::on::#name(__cx, #closure) + // } + // } ElementAttr::EventTokens { name, tokens } => { quote! { dioxus_elements::on::#name(__cx, #tokens) diff --git a/src/lib.rs b/src/lib.rs index 2db210bee..488b1ee9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -353,7 +353,7 @@ pub mod events { pub mod prelude { pub use dioxus_core::prelude::*; - pub use dioxus_core_macro::{format_args_f, inline_props, rsx, Props, Routable}; + pub use dioxus_core_macro::{format_args_f, inline_props, rsx, Props}; pub use dioxus_elements::{GlobalAttributes, SvgAttributes}; pub use dioxus_hooks::*; pub use dioxus_html as dioxus_elements;