feat: more diffing iteration

This commit is contained in:
Jonathan Kelley committed 2022-10-26 18:40:38 -07:00
1 parent 22d4bf7346
commit 67012c38df
3 files changed
+46 -23

No files matched your search

+30 -11
View File
@@ -1013,8 +1013,6 @@ impl<'a, 'b, R: Renderer<'b>> DiffState<'a, 'b, R> {
self.remove_nodes(el.children, false); self.remove_nodes(el.children, false);
self.scopes.collect_garbage(id); self.scopes.collect_garbage(id);
} }
// | VNode::Placeholder(_)
VNode::Text(_) => { VNode::Text(_) => {
let id = old let id = old
.try_mounted_id() .try_mounted_id()
@@ -1023,7 +1021,6 @@ impl<'a, 'b, R: Renderer<'b>> DiffState<'a, 'b, R> {
self.mutations.replace_with(id, nodes_created as u32); self.mutations.replace_with(id, nodes_created as u32);
self.scopes.collect_garbage(id); self.scopes.collect_garbage(id);
} }
VNode::Fragment(f) => { VNode::Fragment(f) => {
self.replace_inner(&f.children[0], nodes_created); self.replace_inner(&f.children[0], nodes_created);
self.remove_nodes(f.children.iter().skip(1), true); self.remove_nodes(f.children.iter().skip(1), true);
@@ -1169,9 +1166,14 @@ impl<'a, 'b, R: Renderer<'b>> DiffState<'a, 'b, R> {
let scope_id = el.scope.get().unwrap(); let scope_id = el.scope.get().unwrap();
search_node = Some(self.scopes.root_node(scope_id)); search_node = Some(self.scopes.root_node(scope_id));
} }
VNode::Template(c) => { VNode::Template(template) => match &template.template.roots[0] {
todo!() TemplateNode::Text(_) | TemplateNode::Element { .. } => {
} // VNode::Placeholder(_) => todo!(), break Some(template.root_ids.last().unwrap().get());
}
TemplateNode::Dynamic(el) => {
search_node = Some(&template.dynamic_nodes[*el].node)
}
},
} }
} }
} }
@@ -1187,9 +1189,14 @@ impl<'a, 'b, R: Renderer<'b>> DiffState<'a, 'b, R> {
let scope = el.scope.get().expect("element to have a scope assigned"); let scope = el.scope.get().expect("element to have a scope assigned");
search_node = Some(self.scopes.root_node(scope)); search_node = Some(self.scopes.root_node(scope));
} }
VNode::Template(t) => { VNode::Template(template) => match &template.template.roots[0] {
todo!() TemplateNode::Text(_) | TemplateNode::Element { .. } => {
} // VNode::Placeholder(_) => todo!(), break Some(template.root_ids[0].get());
}
TemplateNode::Dynamic(el) => {
search_node = Some(&template.dynamic_nodes[*el].node)
}
},
} }
} }
} }
@@ -1215,8 +1222,20 @@ impl<'a, 'b, R: Renderer<'b>> DiffState<'a, 'b, R> {
self.push_all_real_nodes(root) self.push_all_real_nodes(root)
} }
VNode::Template(c) => { VNode::Template(template) => {
todo!() let mut added = 0;
for (idx, root) in template.template.roots.iter().enumerate() {
match root {
TemplateNode::Text(_) | TemplateNode::Element { .. } => {
self.mutations.push_root(template.root_ids[idx].get());
added += 1;
}
TemplateNode::Dynamic(did) => {
added += self.push_all_real_nodes(&template.dynamic_nodes[*did].node);
}
}
}
added
} }
} }
} }
+13 -8
View File
@@ -238,14 +238,19 @@ impl<'a> NodeFactory<'a> {
listeners: &'a [Listener<'a>], listeners: &'a [Listener<'a>],
key: Option<Arguments>, key: Option<Arguments>,
) -> VNode<'a> { ) -> VNode<'a> {
VNode::Template(self.bump.alloc(VTemplate { VNode::Template(
key: None, self.bump.alloc(VTemplate {
node_id: Cell::new(ElementId(0)), key: None,
template, node_id: Cell::new(ElementId(0)),
dynamic_nodes: self.bump.alloc([]), template,
dynamic_attrs: self.bump.alloc([]), dynamic_nodes: self.bump.alloc([]),
listeners, dynamic_attrs: self.bump.alloc([]),
})) listeners,
root_ids:
bumpalo::vec![in self.bump; Cell::new(ElementId(0)); template.roots.len()]
.into_bump_slice(),
}),
)
} }
} }
+3 -4
View File
@@ -9,10 +9,9 @@ pub struct VTemplate<'a> {
// The ID assigned for all nodes in this template // The ID assigned for all nodes in this template
pub node_id: Cell<ElementId>, pub node_id: Cell<ElementId>,
// Position this template for fragments and stuff // All the IDs for the roots of this template
pub head_id: Cell<ElementId>, // Non-assigned IDs are set to 0
pub root_ids: &'a [Cell<ElementId>],
pub tail_id: Cell<ElementId>,
pub template: Template<'static>, pub template: Template<'static>,