refactor diffing a bit
This commit is contained in:
1 parent
d1b9703ee7
commit
0175ae0599
2 files changed
+46
-45
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
innerlude::{ElementRef, WriteMutations},
|
innerlude::{ElementRef, WriteMutations},
|
||||||
nodes::VNode,
|
nodes::VNode,
|
||||||
VirtualDom,
|
DynamicNode, ScopeId, TemplateNode, VirtualDom,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
@@ -424,3 +424,46 @@ impl VirtualDom {
|
|||||||
to.insert_nodes_after(id, m);
|
to.insert_nodes_after(id, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VNode {
|
||||||
|
/// Push all the real nodes on the stack
|
||||||
|
pub(crate) fn push_all_real_nodes(
|
||||||
|
&self,
|
||||||
|
dom: &VirtualDom,
|
||||||
|
to: &mut impl WriteMutations,
|
||||||
|
) -> usize {
|
||||||
|
let template = self.template.get();
|
||||||
|
|
||||||
|
let mount = self.assert_mounted();
|
||||||
|
|
||||||
|
template
|
||||||
|
.roots
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(root_idx, _)| match &self.template.get().roots[root_idx] {
|
||||||
|
TemplateNode::Dynamic { id: idx } => match &self.dynamic_nodes[*idx] {
|
||||||
|
DynamicNode::Placeholder(_) | DynamicNode::Text(_) => {
|
||||||
|
to.push_root(mount.root_ids[root_idx]);
|
||||||
|
1
|
||||||
|
}
|
||||||
|
DynamicNode::Fragment(nodes) => {
|
||||||
|
let mut accumulated = 0;
|
||||||
|
for node in nodes {
|
||||||
|
accumulated += node.push_all_real_nodes(dom, to);
|
||||||
|
}
|
||||||
|
accumulated
|
||||||
|
}
|
||||||
|
DynamicNode::Component(_) => {
|
||||||
|
let scope = ScopeId(mount.mounted_dynamic_nodes[*idx]);
|
||||||
|
let node = dom.get_scope(scope).unwrap().root_node();
|
||||||
|
node.push_all_real_nodes(dom, to)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
to.push_root(mount.root_ids[root_idx]);
|
||||||
|
1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,48 +78,6 @@ impl VNode {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Push all the real nodes on the stack
|
|
||||||
pub(crate) fn push_all_real_nodes(
|
|
||||||
&self,
|
|
||||||
dom: &VirtualDom,
|
|
||||||
to: &mut impl WriteMutations,
|
|
||||||
) -> usize {
|
|
||||||
let template = self.template.get();
|
|
||||||
|
|
||||||
let mount = self.assert_mounted();
|
|
||||||
|
|
||||||
template
|
|
||||||
.roots
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(root_idx, _)| match &self.template.get().roots[root_idx] {
|
|
||||||
Dynamic { id: idx } => match &self.dynamic_nodes[*idx] {
|
|
||||||
Placeholder(_) | Text(_) => {
|
|
||||||
to.push_root(mount.root_ids[root_idx]);
|
|
||||||
1
|
|
||||||
}
|
|
||||||
Fragment(nodes) => {
|
|
||||||
let mut accumulated = 0;
|
|
||||||
for node in nodes {
|
|
||||||
accumulated += node.push_all_real_nodes(dom, to);
|
|
||||||
}
|
|
||||||
accumulated
|
|
||||||
}
|
|
||||||
|
|
||||||
Component(_) => {
|
|
||||||
let scope = ScopeId(mount.mounted_dynamic_nodes[*idx]);
|
|
||||||
let node = dom.get_scope(scope).unwrap().root_node();
|
|
||||||
node.push_all_real_nodes(dom, to)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
to.push_root(mount.root_ids[root_idx]);
|
|
||||||
1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn diff_dynamic_node(
|
fn diff_dynamic_node(
|
||||||
&self,
|
&self,
|
||||||
mount: &mut VNodeMount,
|
mount: &mut VNodeMount,
|
||||||
@@ -314,7 +272,7 @@ impl VNode {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_mounted(&self) -> Ref<'_, VNodeMount> {
|
pub(super) fn assert_mounted(&self) -> Ref<'_, VNodeMount> {
|
||||||
Ref::map(self.mount.borrow(), |mount| {
|
Ref::map(self.mount.borrow(), |mount| {
|
||||||
mount.as_ref().expect("to be mounted")
|
mount.as_ref().expect("to be mounted")
|
||||||
})
|
})
|
||||||
@@ -549,7 +507,7 @@ impl VNode {
|
|||||||
// Simply just load the template root, no modifications needed
|
// Simply just load the template root, no modifications needed
|
||||||
self.load_template_root(mount, idx, dom, to);
|
self.load_template_root(mount, idx, dom, to);
|
||||||
|
|
||||||
// Text producs just one node on the stack
|
// Text produces just one node on the stack
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user