wip: trying to get namespaced elements working

This commit is contained in:
Jonathan Kelley committed 2022-11-15 23:31:23 -08:00
1 parent 04bc635ac5
commit 7f85806fa6
5 files changed
+45 -11

No files matched your search

+6 -4
View File
@@ -8,21 +8,23 @@ fn app(cx: Scope) -> Element {
cx.render(rsx!( cx.render(rsx!(
div { id: "123123123", div { id: "123123123",
// Use Map directly to lazily pull elements // Use Map directly to lazily pull elements
// (0..3).map(|f| rsx! { "{f}" }), (0..10).map(|f| rsx! { "{f}" }),
// Collect into an intermediate collection if necessary, and call into_iter // Collect into an intermediate collection if necessary, and call into_iter
["a", "b", "c", "x", "y", "z"] ["a", "b", "c", "d", "e", "f"]
.into_iter() .into_iter()
.map(|f| rsx! { "{f}" }) .map(|f| rsx! { "{f}" })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter(), .into_iter(),
["d", "e", "f"] ["x", "y", "z"]
.into_iter() .into_iter()
.map(|f| rsx! { "{f}" }) .map(|f| rsx! { "{f}" })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_iter(), .into_iter(),
// Use optionals // Use optionals
// Some(rsx! { "Some" }), Some(rsx! { "Some" }),
} }
)) ))
} }
+28 -6
View File
@@ -45,14 +45,27 @@ impl VirtualDom {
// Walk the roots, creating nodes and assigning IDs // Walk the roots, creating nodes and assigning IDs
// todo: adjust dynamic nodes to be in the order of roots and then leaves (ie BFS) // todo: adjust dynamic nodes to be in the order of roots and then leaves (ie BFS)
let mut dynamic_attrs = template.template.attr_paths.iter().enumerate().peekable(); let mut dynamic_attrs = template
let mut dynamic_nodes = template.template.node_paths.iter().enumerate().peekable(); .template
.attr_paths
.iter()
.enumerate()
.rev()
.peekable();
let mut dynamic_nodes = template
.template
.node_paths
.iter()
.enumerate()
.rev()
.peekable();
let cur_scope = self.scope_stack.last().copied().unwrap(); let cur_scope = self.scope_stack.last().copied().unwrap();
println!("creating template: {:#?}", template); println!("creating template: {:#?}", template);
let mut on_stack = 0; let mut on_stack = 0;
for (root_idx, root) in template.template.roots.iter().enumerate() { for (root_idx, root) in template.template.roots.iter().enumerate().rev() {
mutations.push(LoadTemplate { mutations.push(LoadTemplate {
name: template.template.id, name: template.template.id,
index: root_idx, index: root_idx,
@@ -85,6 +98,7 @@ impl VirtualDom {
AttributeValue::Text(value) => mutations.push(SetAttribute { AttributeValue::Text(value) => mutations.push(SetAttribute {
name: attribute.name, name: attribute.name,
value: *value, value: *value,
ns: attribute.namespace,
id, id,
}), }),
AttributeValue::Bool(value) => mutations.push(SetBoolAttribute { AttributeValue::Bool(value) => mutations.push(SetBoolAttribute {
@@ -163,9 +177,17 @@ impl VirtualDom {
}); });
mutations.extend(attrs.into_iter().filter_map(|attr| match attr { mutations.extend(attrs.into_iter().filter_map(|attr| match attr {
TemplateAttribute::Static { name, value, .. } => { TemplateAttribute::Static {
Some(SetAttribute { name, value, id }) name,
} value,
namespace,
..
} => Some(SetAttribute {
name,
value,
id,
ns: *namespace,
}),
_ => None, _ => None,
})); }));
+1
View File
@@ -130,6 +130,7 @@ impl<'b> VirtualDom {
id: left_attr.mounted_element.get(), id: left_attr.mounted_element.get(),
name: left_attr.name, name: left_attr.name,
value, value,
ns: right_attr.namespace,
}); });
} }
} }
+5
View File
@@ -94,6 +94,11 @@ pub enum Mutation<'a> {
name: &'a str, name: &'a str,
value: &'a str, value: &'a str,
id: ElementId, id: ElementId,
// value: &'bump str,
/// The (optional) namespace of the attribute.
/// For instance, "style" is in the "style" namespace.
ns: Option<&'a str>,
}, },
SetBoolAttribute { SetBoolAttribute {
+5 -1
View File
@@ -258,7 +258,11 @@ export class Interpreter {
this.AssignId(edit.path, edit.id); this.AssignId(edit.path, edit.id);
break; break;
case "CreateElement": case "CreateElement":
this.CreateElement(edit.name, edit.id); if (edit.ns !== null) {
this.CreateElement(edit.name, edit.id, edit.ns);
} else {
this.CreateElement(edit.name, edit.id);
}
break; break;
case "CreatePlaceholder": case "CreatePlaceholder":
this.CreatePlaceholder(edit.id); this.CreatePlaceholder(edit.id);