1
0
Evan Almloff 1 жил өмнө
parent
commit
0175ae0599

+ 44 - 1
packages/core/src/diff/iterator.rs

@@ -1,7 +1,7 @@
 use crate::{
     innerlude::{ElementRef, WriteMutations},
     nodes::VNode,
-    VirtualDom,
+    DynamicNode, ScopeId, TemplateNode, VirtualDom,
 };
 
 use rustc_hash::{FxHashMap, FxHashSet};
@@ -424,3 +424,46 @@ impl VirtualDom {
         to.insert_nodes_after(id, m);
     }
 }
+
+impl VNode {
+    /// Push all the real nodes on the stack
+    pub(crate) fn push_all_real_nodes(
+        &self,
+        dom: &VirtualDom,
+        to: &mut impl WriteMutations,
+    ) -> usize {
+        let template = self.template.get();
+
+        let mount = self.assert_mounted();
+
+        template
+            .roots
+            .iter()
+            .enumerate()
+            .map(|(root_idx, _)| match &self.template.get().roots[root_idx] {
+                TemplateNode::Dynamic { id: idx } => match &self.dynamic_nodes[*idx] {
+                    DynamicNode::Placeholder(_) | DynamicNode::Text(_) => {
+                        to.push_root(mount.root_ids[root_idx]);
+                        1
+                    }
+                    DynamicNode::Fragment(nodes) => {
+                        let mut accumulated = 0;
+                        for node in nodes {
+                            accumulated += node.push_all_real_nodes(dom, to);
+                        }
+                        accumulated
+                    }
+                    DynamicNode::Component(_) => {
+                        let scope = ScopeId(mount.mounted_dynamic_nodes[*idx]);
+                        let node = dom.get_scope(scope).unwrap().root_node();
+                        node.push_all_real_nodes(dom, to)
+                    }
+                },
+                _ => {
+                    to.push_root(mount.root_ids[root_idx]);
+                    1
+                }
+            })
+            .sum()
+    }
+}

+ 2 - 44
packages/core/src/diff/node.rs

@@ -78,48 +78,6 @@ impl VNode {
             });
     }
 
-    /// Push all the real nodes on the stack
-    pub(crate) fn push_all_real_nodes(
-        &self,
-        dom: &VirtualDom,
-        to: &mut impl WriteMutations,
-    ) -> usize {
-        let template = self.template.get();
-
-        let mount = self.assert_mounted();
-
-        template
-            .roots
-            .iter()
-            .enumerate()
-            .map(|(root_idx, _)| match &self.template.get().roots[root_idx] {
-                Dynamic { id: idx } => match &self.dynamic_nodes[*idx] {
-                    Placeholder(_) | Text(_) => {
-                        to.push_root(mount.root_ids[root_idx]);
-                        1
-                    }
-                    Fragment(nodes) => {
-                        let mut accumulated = 0;
-                        for node in nodes {
-                            accumulated += node.push_all_real_nodes(dom, to);
-                        }
-                        accumulated
-                    }
-
-                    Component(_) => {
-                        let scope = ScopeId(mount.mounted_dynamic_nodes[*idx]);
-                        let node = dom.get_scope(scope).unwrap().root_node();
-                        node.push_all_real_nodes(dom, to)
-                    }
-                },
-                _ => {
-                    to.push_root(mount.root_ids[root_idx]);
-                    1
-                }
-            })
-            .sum()
-    }
-
     fn diff_dynamic_node(
         &self,
         mount: &mut VNodeMount,
@@ -314,7 +272,7 @@ impl VNode {
         };
     }
 
-    fn assert_mounted(&self) -> Ref<'_, VNodeMount> {
+    pub(super) fn assert_mounted(&self) -> Ref<'_, VNodeMount> {
         Ref::map(self.mount.borrow(), |mount| {
             mount.as_ref().expect("to be mounted")
         })
@@ -549,7 +507,7 @@ impl VNode {
         // Simply just load the template root, no modifications needed
         self.load_template_root(mount, idx, dom, to);
 
-        // Text producs just one node on the stack
+        // Text produces just one node on the stack
         1
     }