diff --git a/crates/core/src/dom/dom_node.rs b/crates/core/src/dom/dom_node.rs index ec6e8a02..45424bff 100644 --- a/crates/core/src/dom/dom_node.rs +++ b/crates/core/src/dom/dom_node.rs @@ -4,7 +4,6 @@ use crate::dom::GroupedDomAttrValues; use crate::dom::StatefulComponent; use crate::dom::StatefulModel; use crate::html::lookup; -use crate::vdom::TreePath; use crate::{ dom::document, dom::events::MountEvent, @@ -153,7 +152,7 @@ impl PartialEq for DomNode { } impl DomNode { - fn children(&self) -> Option>> { + pub(crate) fn children(&self) -> Option>> { match &self.inner { DomInner::Element { children, .. } => Some(children.borrow()), DomInner::Fragment { children, .. } => Some(children.borrow()), @@ -837,38 +836,3 @@ where } } -pub(crate) fn find_node(target_node: &DomNode, path: &mut TreePath) -> Option { - if path.is_empty() { - Some(target_node.clone()) - } else { - let idx = path.remove_first(); - let children = target_node.children()?; - if let Some(child) = children.get(idx) { - find_node(child, path) - } else { - None - } - } -} - -pub(crate) fn find_all_nodes( - target_node: &DomNode, - nodes_to_find: &[(&TreePath, Option<&&'static str>)], -) -> IndexMap { - let mut nodes_to_patch: IndexMap = - IndexMap::with_capacity(nodes_to_find.len()); - for (path, tag) in nodes_to_find { - let mut traverse_path: TreePath = (*path).clone(); - if let Some(found) = find_node(target_node, &mut traverse_path) { - nodes_to_patch.insert((*path).clone(), found); - } else { - log::warn!( - "can not find: {:?} {:?} target_node: {:?}", - path, - tag, - target_node - ); - } - } - nodes_to_patch -} diff --git a/crates/core/src/dom/dom_patch.rs b/crates/core/src/dom/dom_patch.rs index 8e408c37..e402cf2b 100644 --- a/crates/core/src/dom/dom_patch.rs +++ b/crates/core/src/dom/dom_patch.rs @@ -1,5 +1,4 @@ use crate::dom; -use crate::dom::dom_node::find_all_nodes; use crate::dom::dom_node::DomInner; use crate::dom::DomAttr; use crate::dom::DomAttrValue; @@ -77,6 +76,46 @@ pub enum PatchVariant { }, } +impl DomNode{ + + pub(crate) fn find_node(&self, path: &mut TreePath) -> Option { + if path.is_empty() { + Some(self.clone()) + } else { + let idx = path.remove_first(); + let children = self.children()?; + if let Some(child) = children.get(idx) { + child.find_node(path) + } else { + None + } + } + } + + pub(crate) fn find_all_nodes( + &self, + nodes_to_find: &[(&TreePath, Option<&&'static str>)], + ) -> IndexMap { + let mut nodes_to_patch: IndexMap = + IndexMap::with_capacity(nodes_to_find.len()); + for (path, tag) in nodes_to_find { + let mut traverse_path: TreePath = (*path).clone(); + if let Some(found) = self.find_node(&mut traverse_path) { + nodes_to_patch.insert((*path).clone(), found); + } else { + log::warn!( + "can not find: {:?} {:?} target_node: {:?}", + path, + tag, + &self + ); + } + } + nodes_to_patch + } +} + + impl Program where APP: Application + 'static, @@ -150,7 +189,7 @@ where ) .collect(); - let nodes_lookup = find_all_nodes(target_node, &nodes_to_find); + let nodes_lookup = target_node.find_all_nodes(&nodes_to_find); let dom_patches:Vec = patches.iter().map(|patch|{ let patch_path = patch.path();