wip: structure coming together and tests

This commit is contained in:
Jonathan Kelley committed 2021-08-23 12:11:45 -04:00
1 parent 16bfc6d248
commit 2d541eca64
13 files changed
+251 -141

No files matched your search

+13 -15
View File
@@ -16,7 +16,6 @@ pub enum DiffInstruction<'a> {
Create {
node: &'a VNode<'a>,
and: MountType<'a>,
},
Remove {
@@ -41,13 +40,14 @@ pub enum MountType<'a> {
Absorb,
Append,
Replace { old: &'a VNode<'a> },
InsertAfter { other_node: Option<&'a VNode<'a>> },
InsertBefore { other_node: Option<&'a VNode<'a>> },
ReplaceByElementId { old: ElementId },
InsertAfter { other_node: &'a VNode<'a> },
InsertBefore { other_node: &'a VNode<'a> },
}
pub struct DiffStack<'bump> {
pub instructions: Vec<DiffInstruction<'bump>>,
pub nodes_created_stack: SmallVec<[usize; 10]>,
instructions: Vec<DiffInstruction<'bump>>,
nodes_created_stack: SmallVec<[usize; 10]>,
pub scope_stack: SmallVec<[ScopeId; 5]>,
}
@@ -77,24 +77,25 @@ impl<'bump> DiffStack<'bump> {
self.instructions.push(DiffInstruction::Mount { and });
for child in children.into_iter().rev() {
self.instructions.push(DiffInstruction::Create {
and: MountType::Absorb,
node: child,
});
self.instructions
.push(DiffInstruction::Create { node: child });
}
}
pub fn create_node(&mut self, node: &'bump VNode<'bump>, and: MountType<'bump>) {
self.nodes_created_stack.push(0);
self.instructions.push(DiffInstruction::Mount { and });
self.instructions
.push(DiffInstruction::Create { and, node });
self.instructions.push(DiffInstruction::Create { node });
}
pub fn add_child_count(&mut self, count: usize) {
*self.nodes_created_stack.last_mut().unwrap() += count;
}
pub fn pop_nodes_created(&mut self) -> usize {
self.nodes_created_stack.pop().unwrap()
}
pub fn current_scope(&self) -> Option<ScopeId> {
self.scope_stack.last().map(|f| f.clone())
}
@@ -107,9 +108,6 @@ impl<'bump> DiffStack<'bump> {
// Run the creation algorithm with this scope on the stack
// ?? I think we treat components as framgnets??
self.instructions.push(DiffInstruction::Create {
node,
and: MountType::Absorb,
});
self.instructions.push(DiffInstruction::Create { node });
}
}