Skip to content

Commit

Permalink
Updated vlist to have key() attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrh0057 committed Apr 5, 2020
1 parent c9b528c commit 394141d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/virtual_dom/vlist.rs
Expand Up @@ -60,6 +60,22 @@ impl VList {
pub fn add_child(&mut self, child: VNode) {
self.children.push(child);
}

pub fn key(&self) -> Option<String> {
let mut key = String::with_capacity(150);
const START_STRING: &str = "#vlist_";
key.push_str(START_STRING);
for n in &self.children{
if let Some(child_key) = &n.key() {
key = key + child_key;
}
}
if START_STRING == &key {
None
} else {
Some(key)
}
}
}

impl VDiff for VList {
Expand Down
2 changes: 1 addition & 1 deletion src/virtual_dom/vnode.rs
Expand Up @@ -37,7 +37,7 @@ impl VNode {
VNode::VTag(vtag) => vtag.key.clone(),
VNode::VText(_) => None,
VNode::VComp(vcomp) => vcomp.key.clone(),
VNode::VList(_) => None,
VNode::VList(vnode) => vnode.key().clone(),
VNode::VRef(_) => None,
}
}
Expand Down

0 comments on commit 394141d

Please sign in to comment.