1
0
Evan Almloff 1 жил өмнө
parent
commit
8d14671520

+ 2 - 3
examples/spread.rs

@@ -9,7 +9,7 @@ fn main() {
 
 fn app() -> Element {
     render! {
-        Component {
+        spreadable_component {
             width: "10px",
             extra_data: "hello{1}",
             extra_data2: "hello{2}",
@@ -19,8 +19,7 @@ fn app() -> Element {
     }
 }
 
-#[component]
-fn Component(props: Props) -> Element {
+fn spreadable_component(props: Props) -> Element {
     render! {
         audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" }
     }

+ 2 - 2
packages/rsx/src/attribute.rs

@@ -38,8 +38,8 @@ impl AttributeType {
 impl ToTokens for AttributeType {
     fn to_tokens(&self, tokens: &mut TokenStream2) {
         match self {
-            AttributeType::Named(n) => tokens.append_all(quote! { #n }),
-            AttributeType::Spread(e) => tokens.append_all(quote! { (&#e).into() }),
+            AttributeType::Named(n) => tokens.append_all(quote! { Box::new([#n]) }),
+            AttributeType::Spread(e) => tokens.append_all(quote! { #e.into_boxed_slice() }),
         }
     }
 }

+ 0 - 48
packages/rsx/src/element.rs

@@ -243,54 +243,6 @@ Like so:
     }
 }
 
-impl ToTokens for Element {
-    fn to_tokens(&self, tokens: &mut TokenStream2) {
-        let name = &self.name;
-        let children = &self.children;
-
-        let key = match &self.key {
-            Some(ty) => quote! { Some(#ty) },
-            None => quote! { None },
-        };
-
-        let listeners = self.merged_attributes.iter().filter(|f| {
-            matches!(
-                f,
-                AttributeType::Named(ElementAttrNamed {
-                    attr: ElementAttr {
-                        value: ElementAttrValue::EventTokens { .. },
-                        ..
-                    },
-                    ..
-                })
-            )
-        });
-
-        let attr = self.merged_attributes.iter().filter(|f| {
-            !matches!(
-                f,
-                AttributeType::Named(ElementAttrNamed {
-                    attr: ElementAttr {
-                        value: ElementAttrValue::EventTokens { .. },
-                        ..
-                    },
-                    ..
-                })
-            )
-        });
-
-        tokens.append_all(quote! {
-            dioxus_core::Element::new(
-                #name,
-                vec![ #(#listeners),* ],
-                vec![ #(#attr),* ],
-                vec![ #(#children),* ],
-                #key,
-            )
-        });
-    }
-}
-
 #[derive(PartialEq, Eq, Clone, Debug, Hash)]
 pub enum ElementName {
     Ident(Ident),

+ 1 - 1
packages/rsx/src/lib.rs

@@ -257,7 +257,7 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
                 #key_tokens,
                 TEMPLATE,
                 Box::new([ #( #node_printer),* ]),
-                Box::new([ #( Box::new([ #( #dyn_attr_printer),* ]) ),* ]),
+                Box::new([ #( #(#dyn_attr_printer),* ),* ]),
             )
         });
     }

+ 3 - 1
packages/rsx/src/node.rs

@@ -139,7 +139,9 @@ impl Parse for BodyNode {
 impl ToTokens for BodyNode {
     fn to_tokens(&self, tokens: &mut TokenStream2) {
         match &self {
-            BodyNode::Element(el) => el.to_tokens(tokens),
+            BodyNode::Element(_) => {
+                unimplemented!("Elements are statically created in the template")
+            }
             BodyNode::Component(comp) => comp.to_tokens(tokens),
             BodyNode::Text(txt) => tokens.append_all(quote! {
                 dioxus_core::DynamicNode::Text(dioxus_core::VText::new(#txt))