hello world example working

This commit is contained in:
Evan Almloff committed 2024-01-05 18:01:05 -06:00
1 parent 3865f44081
commit 4013341b6c
22 files changed
+159 -176

No files matched your search

+2 -2
View File
@@ -68,7 +68,7 @@ impl ToTokens for ElementAttrNamed {
let value = &self.attr.value;
let value = quote! { #value };
quote! {
__cx.attr(
::dioxus::core::Attribute::new(
#attribute,
#value,
#ns,
@@ -79,7 +79,7 @@ impl ToTokens for ElementAttrNamed {
ElementAttrValue::EventTokens(tokens) => match &self.attr.name {
ElementAttrName::BuiltIn(name) => {
quote! {
dioxus_elements::events::#name(__cx, #tokens)
dioxus_elements::events::#name(#tokens)
}
}
ElementAttrName::Custom(_) => todo!(),
+4 -4
View File
@@ -189,11 +189,11 @@ impl ToTokens for Component {
};
tokens.append_all(quote! {
__cx.component(
::dioxus::core::DynamicNode::Component(::dioxus::core::VComponent::new(
#gen_name,
#builder,
#fn_name
)
))
})
}
}
@@ -217,10 +217,10 @@ impl ToTokens for ContentField {
match self {
ContentField::ManExpr(e) => e.to_tokens(tokens),
ContentField::Formatted(s) => tokens.append_all(quote! {
__cx.raw_text(#s)
#s.to_string()
}),
ContentField::OnHandlerRaw(e) => tokens.append_all(quote! {
__cx.event_handler(#e)
::dioxus::core::Attribute::EventHandler(EventHandler::new(#e))
}),
}
}
+4 -4
View File
@@ -184,11 +184,11 @@ impl ToTokens for Element {
.filter(|f| !matches!(f.attr.value, ElementAttrValue::EventTokens { .. }));
tokens.append_all(quote! {
__cx.element(
::dioxus::core::Element::new(
#name,
__cx.bump().alloc([ #(#listeners),* ]),
__cx.bump().alloc([ #(#attr),* ]),
__cx.bump().alloc([ #(#children),* ]),
vec![ #(#listeners),* ],
vec![ #(#attr),* ],
vec![ #(#children),* ],
#key,
)
});
+7 -8
View File
@@ -69,7 +69,7 @@ impl CallBody {
&self,
template: Option<CallBody>,
location: &'static str,
) -> Option<Template<'static>> {
) -> Option<Template> {
let mut renderer: TemplateRenderer = TemplateRenderer {
roots: &self.roots,
location: None,
@@ -138,7 +138,6 @@ impl ToTokens for RenderCallBody {
out_tokens.append_all(quote! {
Some({
let __cx = cx;
#body
})
})
@@ -156,7 +155,7 @@ impl<'a> TemplateRenderer<'a> {
&mut self,
previous_call: Option<CallBody>,
location: &'static str,
) -> Option<Template<'static>> {
) -> Option<Template> {
let mut mapping = previous_call.map(|call| DynamicMapping::from(call.roots));
let mut context = DynamicContext::default();
@@ -202,7 +201,7 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
};
let key_tokens = match key {
Some(tok) => quote! { Some( __cx.raw_text(#tok) ) },
Some(tok) => quote! { Some( #tok.to_string() ) },
None => quote! { None },
};
@@ -257,9 +256,9 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
::dioxus::core::VNode::new(
#key_tokens,
TEMPLATE,
dioxus::core::exports::bumpalo::collections::Vec::with_capacity_in(#root_count, __cx.bump()),
__cx.bump().alloc([ #( #node_printer ),* ]),
__cx.bump().alloc([ #( #dyn_attr_printer ),* ]),
Vec::with_capacity(#root_count),
vec![ #( #node_printer ),* ],
vec![ #( #dyn_attr_printer ),* ],
)
});
}
@@ -360,7 +359,7 @@ impl<'a> DynamicContext<'a> {
&mut self,
root: &'a BodyNode,
mapping: &mut Option<DynamicMapping>,
) -> Option<TemplateNode<'static>> {
) -> Option<TemplateNode> {
match root {
BodyNode::Element(el) => {
let element_name_rust = el.name.to_string();
+5 -5
View File
@@ -122,11 +122,11 @@ impl ToTokens for BodyNode {
BodyNode::Element(el) => el.to_tokens(tokens),
BodyNode::Component(comp) => comp.to_tokens(tokens),
BodyNode::Text(txt) => tokens.append_all(quote! {
__cx.text_node(#txt)
::dioxus::core::DynamicNode::Text(::dioxus::core::VText::new(#txt.to_string()))
}),
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
{
let ___nodes = (#exp).into_dyn_node(__cx);
let ___nodes = (#exp).into_dyn_node();
___nodes
}
}),
@@ -145,7 +145,7 @@ impl ToTokens for BodyNode {
// And then we can return them into the dyn loop
tokens.append_all(quote! {
{
let ___nodes =(#expr).into_iter().map(|#pat| { #renderer }).into_dyn_node(__cx);
let ___nodes = (#expr).into_iter().map(|#pat| { #renderer }).into_dyn_node();
___nodes
}
})
@@ -154,7 +154,7 @@ impl ToTokens for BodyNode {
if is_if_chain_terminated(chain) {
tokens.append_all(quote! {
{
let ___nodes = (#chain).into_dyn_node(__cx);
let ___nodes = (#chain).into_dyn_node();
___nodes
}
});
@@ -211,7 +211,7 @@ impl ToTokens for BodyNode {
tokens.append_all(quote! {
{
let ___nodes = (#body).into_dyn_node(__cx);
let ___nodes = (#body).into_dyn_node();
___nodes
}
});