fix: make listeners up to date
This commit is contained in:
1 parent
185902f935
commit
9438cc14bc
2 files changed
+42
-44
No files matched your search
+41
-43
@@ -4,7 +4,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||||||
use quote::{quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseBuffer, ParseStream},
|
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::<Token![:]>()?;
|
content.parse::<Token![:]>()?;
|
||||||
|
|
||||||
if name_str.starts_with("on") {
|
if name_str.starts_with("on") {
|
||||||
if content.fork().parse::<ExprClosure>().is_ok() {
|
attributes.push(ElementAttrNamed {
|
||||||
//
|
el_name: el_name.clone(),
|
||||||
attributes.push(ElementAttrNamed {
|
attr: ElementAttr::EventTokens {
|
||||||
el_name: el_name.clone(),
|
name,
|
||||||
attr: ElementAttr::EventClosure {
|
tokens: content.parse()?,
|
||||||
name,
|
},
|
||||||
closure: content.parse()?,
|
});
|
||||||
},
|
// if content.fork().parse::<ExprClosure>().is_ok() {
|
||||||
});
|
// //
|
||||||
} else {
|
// attributes.push(ElementAttrNamed {
|
||||||
attributes.push(ElementAttrNamed {
|
// el_name: el_name.clone(),
|
||||||
el_name: el_name.clone(),
|
// attr: ElementAttr::EventClosure {
|
||||||
attr: ElementAttr::EventTokens {
|
// name,
|
||||||
name,
|
// closure: content.parse()?,
|
||||||
tokens: content.parse()?,
|
// },
|
||||||
},
|
// });
|
||||||
});
|
// } else {
|
||||||
}
|
// attributes.push(ElementAttrNamed {
|
||||||
|
// el_name: el_name.clone(),
|
||||||
|
// attr: ElementAttr::EventTokens {
|
||||||
|
// name,
|
||||||
|
// tokens: content.parse()?,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
match name_str.as_str() {
|
match name_str.as_str() {
|
||||||
"key" => {
|
"key" => {
|
||||||
@@ -203,28 +210,20 @@ impl ToTokens for Element {
|
|||||||
let name = &self.name;
|
let name = &self.name;
|
||||||
let children = &self.children;
|
let children = &self.children;
|
||||||
|
|
||||||
// let listeners = &self.listeners;
|
|
||||||
|
|
||||||
let key = match &self.key {
|
let key = match &self.key {
|
||||||
Some(ty) => quote! { Some(format_args_f!(#ty)) },
|
Some(ty) => quote! { Some(format_args_f!(#ty)) },
|
||||||
None => quote! { None },
|
None => quote! { None },
|
||||||
};
|
};
|
||||||
|
|
||||||
let listeners = self.attributes.iter().filter(|f| {
|
let listeners = self
|
||||||
if let ElementAttr::EventTokens { .. } = f.attr {
|
.attributes
|
||||||
true
|
.iter()
|
||||||
} else {
|
.filter(|f| matches!(f.attr, ElementAttr::EventTokens { .. }));
|
||||||
false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let attr = self.attributes.iter().filter(|f| {
|
let attr = self
|
||||||
if let ElementAttr::EventTokens { .. } = f.attr {
|
.attributes
|
||||||
false
|
.iter()
|
||||||
} else {
|
.filter(|f| !matches!(f.attr, ElementAttr::EventTokens { .. }));
|
||||||
true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
__cx.element(
|
__cx.element(
|
||||||
@@ -251,9 +250,8 @@ pub enum ElementAttr {
|
|||||||
/// "attribute": true,
|
/// "attribute": true,
|
||||||
CustomAttrExpression { name: LitStr, value: Expr },
|
CustomAttrExpression { name: LitStr, value: Expr },
|
||||||
|
|
||||||
/// onclick: move |_| {}
|
// /// onclick: move |_| {}
|
||||||
EventClosure { name: Ident, closure: ExprClosure },
|
// EventClosure { name: Ident, closure: ExprClosure },
|
||||||
|
|
||||||
/// onclick: {}
|
/// onclick: {}
|
||||||
EventTokens { name: Ident, tokens: Expr },
|
EventTokens { name: Ident, tokens: Expr },
|
||||||
}
|
}
|
||||||
@@ -288,11 +286,11 @@ impl ToTokens for ElementAttrNamed {
|
|||||||
__cx.attr( #name, format_args_f!(#value), None, false )
|
__cx.attr( #name, format_args_f!(#value), None, false )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ElementAttr::EventClosure { name, closure } => {
|
// ElementAttr::EventClosure { name, closure } => {
|
||||||
quote! {
|
// quote! {
|
||||||
dioxus_elements::on::#name(__cx, #closure)
|
// dioxus_elements::on::#name(__cx, #closure)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
ElementAttr::EventTokens { name, tokens } => {
|
ElementAttr::EventTokens { name, tokens } => {
|
||||||
quote! {
|
quote! {
|
||||||
dioxus_elements::on::#name(__cx, #tokens)
|
dioxus_elements::on::#name(__cx, #tokens)
|
||||||
|
|||||||
+1
-1
@@ -353,7 +353,7 @@ pub mod events {
|
|||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use dioxus_core::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_elements::{GlobalAttributes, SvgAttributes};
|
||||||
pub use dioxus_hooks::*;
|
pub use dioxus_hooks::*;
|
||||||
pub use dioxus_html as dioxus_elements;
|
pub use dioxus_html as dioxus_elements;
|
||||||
|
|||||||
Reference in new issue
Block a user