wip: prep to fix bug in create
This commit is contained in:
1 parent
e09b6bf813
commit
04bc635ac5
14 files changed
+539
-57
No files matched your search
+16
-14
@@ -49,20 +49,19 @@ impl VirtualDom {
|
||||
let mut dynamic_nodes = template.template.node_paths.iter().enumerate().peekable();
|
||||
let cur_scope = self.scope_stack.last().copied().unwrap();
|
||||
|
||||
println!("creating template: {:#?}", template);
|
||||
|
||||
let mut on_stack = 0;
|
||||
for (root_idx, root) in template.template.roots.iter().enumerate() {
|
||||
on_stack += match root {
|
||||
TemplateNode::Element { .. }
|
||||
| TemplateNode::Text(_)
|
||||
| TemplateNode::DynamicText { .. } => {
|
||||
mutations.push(LoadTemplate {
|
||||
name: template.template.id,
|
||||
index: root_idx,
|
||||
});
|
||||
1
|
||||
}
|
||||
mutations.push(LoadTemplate {
|
||||
name: template.template.id,
|
||||
index: root_idx,
|
||||
});
|
||||
|
||||
TemplateNode::Dynamic(id) => {
|
||||
on_stack += match root {
|
||||
TemplateNode::Element { .. } | TemplateNode::Text(_) => 1,
|
||||
|
||||
TemplateNode::DynamicText(id) | TemplateNode::Dynamic(id) => {
|
||||
self.create_dynamic_node(mutations, template, &template.dynamic_nodes[*id], *id)
|
||||
}
|
||||
};
|
||||
@@ -268,9 +267,12 @@ impl VirtualDom {
|
||||
}
|
||||
}
|
||||
|
||||
DynamicNode::Fragment { nodes, .. } => nodes
|
||||
.iter()
|
||||
.fold(0, |acc, child| acc + self.create(mutations, child)),
|
||||
DynamicNode::Fragment { nodes, .. } => {
|
||||
//
|
||||
nodes
|
||||
.iter()
|
||||
.fold(0, |acc, child| acc + self.create(mutations, child))
|
||||
}
|
||||
|
||||
DynamicNode::Placeholder(_) => {
|
||||
let id = self.next_element(template);
|
||||
|
||||
@@ -160,8 +160,10 @@ impl<'a, 'b> IntoDynNode<'a> for VNode<'a> {
|
||||
|
||||
impl<'a, 'b, T: IntoDynNode<'a>> IntoDynNode<'a> for Option<T> {
|
||||
fn into_vnode(self, _cx: &'a ScopeState) -> DynamicNode<'a> {
|
||||
// DynamicNode::Fragment { nodes: cx., inner: () }
|
||||
todo!()
|
||||
match self {
|
||||
Some(val) => val.into_vnode(_cx),
|
||||
None => DynamicNode::Placeholder(Default::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::{
|
||||
pub type TemplateId = &'static str;
|
||||
|
||||
/// A reference to a template along with any context needed to hydrate it
|
||||
#[derive(Debug)]
|
||||
pub struct VNode<'a> {
|
||||
// The ID assigned for the root of this template
|
||||
pub node_id: Cell<ElementId>,
|
||||
@@ -106,6 +107,7 @@ pub enum TemplateNode<'a> {
|
||||
DynamicText(usize),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DynamicNode<'a> {
|
||||
Component {
|
||||
name: &'static str,
|
||||
@@ -137,6 +139,7 @@ pub enum TemplateAttribute<'a> {
|
||||
Dynamic(usize),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Attribute<'a> {
|
||||
pub name: &'a str,
|
||||
pub value: AttributeValue<'a>,
|
||||
|
||||
Reference in new issue
Block a user