feat: more tests working
This commit is contained in:
1 parent
4dd9a616a5
commit
0cfbfc88e2
16 files changed
+568
-248
No files matched your search
+19
-17
@@ -216,12 +216,10 @@ impl<'b: 'static> VirtualDom {
|
||||
) {
|
||||
match *node {
|
||||
// Todo: create the children's template
|
||||
TemplateNode::Dynamic(_) => {
|
||||
let id = ElementId(0);
|
||||
self.mutations
|
||||
.template_mutations
|
||||
.push(CreatePlaceholder { id })
|
||||
}
|
||||
TemplateNode::Dynamic(_) => self
|
||||
.mutations
|
||||
.template_mutations
|
||||
.push(CreateStaticPlaceholder {}),
|
||||
TemplateNode::Text(value) => self
|
||||
.mutations
|
||||
.template_mutations
|
||||
@@ -236,15 +234,20 @@ impl<'b: 'static> VirtualDom {
|
||||
children,
|
||||
namespace,
|
||||
tag,
|
||||
inner_opt,
|
||||
..
|
||||
} => {
|
||||
let id = ElementId(0);
|
||||
|
||||
self.mutations.template_mutations.push(CreateElement {
|
||||
name: tag,
|
||||
namespace,
|
||||
id,
|
||||
});
|
||||
if let Some(namespace) = namespace {
|
||||
self.mutations
|
||||
.template_mutations
|
||||
.push(CreateElementNamespace {
|
||||
name: tag,
|
||||
namespace,
|
||||
});
|
||||
} else {
|
||||
self.mutations
|
||||
.template_mutations
|
||||
.push(CreateElement { name: tag });
|
||||
}
|
||||
|
||||
self.mutations
|
||||
.template_mutations
|
||||
@@ -254,16 +257,15 @@ impl<'b: 'static> VirtualDom {
|
||||
value,
|
||||
namespace,
|
||||
..
|
||||
} => Some(SetAttribute {
|
||||
} => Some(SetStaticAttribute {
|
||||
name,
|
||||
value,
|
||||
id,
|
||||
ns: *namespace,
|
||||
}),
|
||||
_ => None,
|
||||
}));
|
||||
|
||||
if children.is_empty() && inner_opt {
|
||||
if children.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,8 +239,72 @@ impl<'b: 'static> VirtualDom {
|
||||
//
|
||||
// Remove the old nodes, except for one
|
||||
self.remove_nodes(&l[1..]);
|
||||
let id = self.next_element(&l[0], &[]);
|
||||
// self.replace(left_template, right_template, left, right)
|
||||
let first = self.find_first_element(&l[0]);
|
||||
self.remove_all_but_first_node(&l[0]);
|
||||
|
||||
let placeholder = self.next_element(&l[0], &[]);
|
||||
r.set(placeholder);
|
||||
self.mutations
|
||||
.push(Mutation::CreatePlaceholder { id: placeholder });
|
||||
self.mutations
|
||||
.push(Mutation::ReplaceWith { id: first, m: 1 })
|
||||
}
|
||||
|
||||
// Remove all the top-level nodes, returning the
|
||||
fn remove_all_but_first_node(&mut self, node: &'b VNode<'b>) {
|
||||
match &node.template.roots[0] {
|
||||
TemplateNode::Text(_) | TemplateNode::Element { .. } => {}
|
||||
TemplateNode::DynamicText(id) | TemplateNode::Dynamic(id) => {
|
||||
match &node.dynamic_nodes[*id] {
|
||||
Text(_) => {}
|
||||
Fragment(VFragment::Empty(_)) => {}
|
||||
Fragment(VFragment::NonEmpty(nodes)) => {
|
||||
self.remove_all_but_first_node(&nodes[0]);
|
||||
self.remove_nodes(&nodes[1..]);
|
||||
}
|
||||
Component(comp) => {
|
||||
let scope = comp.scope.get().unwrap();
|
||||
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
|
||||
RenderReturn::Sync(Ok(t)) => self.remove_all_but_first_node(t),
|
||||
_ => todo!("cannot handle nonstandard nodes"),
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Just remove the rest
|
||||
for (idx, _) in node.template.roots.iter().enumerate().skip(1) {
|
||||
self.remove_root_node(node, idx);
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_root_node(&mut self, node: &'b VNode<'b>, idx: usize) {
|
||||
let root = node.template.roots[idx];
|
||||
match root {
|
||||
TemplateNode::Element { .. } | TemplateNode::Text(_) => {
|
||||
self.mutations.push(Mutation::Remove {
|
||||
id: node.root_ids[idx].get(),
|
||||
})
|
||||
}
|
||||
|
||||
TemplateNode::DynamicText(id) | TemplateNode::Dynamic(id) => {
|
||||
match &node.dynamic_nodes[id] {
|
||||
Text(i) => self.mutations.push(Mutation::Remove { id: i.id.get() }),
|
||||
Fragment(VFragment::Empty(e)) => {
|
||||
self.mutations.push(Mutation::Remove { id: e.get() })
|
||||
}
|
||||
Fragment(VFragment::NonEmpty(nodes)) => self.remove_nodes(nodes),
|
||||
Component(comp) => {
|
||||
let scope = comp.scope.get().unwrap();
|
||||
match unsafe { self.scopes[scope.0].root_node().extend_lifetime_ref() } {
|
||||
RenderReturn::Sync(Ok(t)) => self.remove_node(t),
|
||||
_ => todo!("cannot handle nonstandard nodes"),
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn diff_non_empty_fragment(&mut self, new: &'b [VNode<'b>], old: &'b [VNode<'b>]) {
|
||||
|
||||
@@ -96,7 +96,7 @@ impl<'a> Properties for FragmentProps<'a> {
|
||||
type Builder = FragmentBuilder<'a, false>;
|
||||
const IS_STATIC: bool = false;
|
||||
fn builder() -> Self::Builder {
|
||||
todo!()
|
||||
FragmentBuilder(VNode::empty())
|
||||
}
|
||||
unsafe fn memoize(&self, _other: &Self) -> bool {
|
||||
false
|
||||
|
||||
@@ -72,13 +72,15 @@ pub enum Mutation<'a> {
|
||||
|
||||
CreateElement {
|
||||
name: &'a str,
|
||||
namespace: Option<&'a str>,
|
||||
id: ElementId,
|
||||
},
|
||||
|
||||
CreateElementNamespace {
|
||||
name: &'a str,
|
||||
namespace: &'a str,
|
||||
},
|
||||
CreatePlaceholder {
|
||||
id: ElementId,
|
||||
},
|
||||
CreateStaticPlaceholder,
|
||||
CreateStaticText {
|
||||
value: &'a str,
|
||||
},
|
||||
@@ -142,6 +144,12 @@ pub enum Mutation<'a> {
|
||||
ns: Option<&'a str>,
|
||||
},
|
||||
|
||||
SetStaticAttribute {
|
||||
name: &'a str,
|
||||
value: &'a str,
|
||||
ns: Option<&'a str>,
|
||||
},
|
||||
|
||||
SetBoolAttribute {
|
||||
name: &'a str,
|
||||
value: bool,
|
||||
|
||||
Reference in new issue
Block a user