wip: pre vnodes instead of vnode

This commit is contained in:
Jonathan Kelley committed 2021-06-08 14:00:29 -04:00
1 parent e3d9db0847
commit fe6938ceb3
21 files changed
+303 -441

No files matched your search

+3 -9
View File
@@ -50,15 +50,9 @@ impl Parse for AmbiguousElement {
false => {
let first_char = name_str.chars().next().unwrap();
if first_char.is_ascii_uppercase() {
if name_str == "Fragment" {
input
.parse::<Fragment>()
.map(|c| AmbiguousElement::Fragment(c))
} else {
input
.parse::<Component>()
.map(|c| AmbiguousElement::Component(c))
}
input
.parse::<Component>()
.map(|c| AmbiguousElement::Component(c))
} else {
let name = input.parse::<Ident>().unwrap();
Err(Error::new(
+35 -11
View File
@@ -26,7 +26,7 @@ pub struct Component {
// accept any path-like argument
name: syn::Path,
body: Vec<ComponentField>,
_children: Vec<Node>,
children: Vec<Node>,
}
impl Parse for Component {
@@ -41,7 +41,7 @@ impl Parse for Component {
syn::braced!(content in s);
let mut body: Vec<ComponentField> = Vec::new();
let _children: Vec<Node> = Vec::new();
let mut children: Vec<Node> = Vec::new();
'parsing: loop {
// [1] Break if empty
@@ -49,7 +49,7 @@ impl Parse for Component {
break 'parsing;
}
if content.peek(token::Brace) {
if content.peek(token::Brace) && content.peek2(Token![...]) {
let inner: ParseBuffer;
syn::braced!(inner in content);
if inner.peek(Token![...]) {
@@ -57,7 +57,11 @@ impl Parse for Component {
}
}
body.push(content.parse::<ComponentField>()?);
if content.peek(Ident) && content.peek2(Token![:]) {
body.push(content.parse::<ComponentField>()?);
} else {
children.push(content.parse::<Node>()?);
}
// consume comma if it exists
// we don't actually care if there *are* commas between attrs
@@ -66,13 +70,10 @@ impl Parse for Component {
}
}
// todo: add support for children
let children: Vec<Node> = vec![];
Ok(Self {
name,
body,
_children: children,
children,
})
}
}
@@ -109,9 +110,32 @@ impl ToTokens for Component {
None => quote! {None},
};
let _toks = tokens.append_all(quote! {
dioxus::builder::virtual_child(__ctx, #name, #builder, #key_token)
});
let childs = &self.children;
let children = quote! {
ChildrenList::new(__ctx)
#( .add_child(#childs) )*
.finish()
};
let name_str = name.segments.last().unwrap().ident.to_string();
match name_str.as_str() {
"Fragment" => tokens.append_all(quote! {
dioxus::builder::vfragment(
__ctx,
#key_token,
#children
)
}),
_ => tokens.append_all(quote! {
dioxus::builder::virtual_child(
__ctx,
#name,
#builder,
#key_token,
#children
)
}),
}
// }
}
}
+20 -8
View File
@@ -133,6 +133,10 @@ impl Parse for ElementAttr {
}
} else {
match name_str.as_str() {
"key" => {
// todo: better error here
AttrType::BumpText(s.parse::<LitStr>()?)
}
"style" => {
//
todo!("inline style not yet supported")
@@ -196,10 +200,23 @@ impl ToTokens for ElementAttr {
let name = self.name.to_string();
let nameident = &self.name;
let _attr_stream = TokenStream2::new();
match &self.ty {
AttrType::BumpText(value) => {
AttrType::BumpText(value) => match name.as_str() {
"key" => {
tokens.append_all(quote! {
.key2(format_args_f!(#value))
});
}
_ => {
tokens.append_all(quote! {
.attr(#name, format_args_f!(#value))
});
}
},
AttrType::FieldTokens(exp) => {
tokens.append_all(quote! {
.attr(#name, format_args_f!(#value))
.attr(#name, #exp)
});
}
AttrType::Event(event) => {
@@ -207,16 +224,11 @@ impl ToTokens for ElementAttr {
.add_listener(dioxus::events::on::#nameident(__ctx, #event))
});
}
AttrType::FieldTokens(exp) => {
tokens.append_all(quote! {
.attr(#name, #exp)
});
}
AttrType::EventTokens(event) => {
//
tokens.append_all(quote! {
.add_listener(dioxus::events::on::#nameident(__ctx, #event))
})
});
}
}
}