Преглед изворни кода

assign parents through fragments

Evan Almloff пре 1 година
родитељ
комит
d81d3ebaef

+ 1 - 1
packages/core/src/create.rs

@@ -485,7 +485,7 @@ impl<'b> VirtualDom {
             Text(text) => self.create_dynamic_text(parent, text),
             Placeholder(place) => self.create_placeholder(place, parent),
             Component(component) => self.create_component_node(Some(parent), component),
-            Fragment(frag) => frag.iter().map(|child| self.create(child)).sum(),
+            Fragment(frag) => self.create_children(*frag, Some(parent)),
         }
     }
 

+ 8 - 5
packages/core/src/diff.rs

@@ -776,15 +776,18 @@ impl<'b> VirtualDom {
             .sum()
     }
 
-    fn create_children(
+    pub(crate) fn create_children(
         &mut self,
         nodes: impl IntoIterator<Item = &'b VNode<'b>>,
         parent: Option<ElementRef>,
     ) -> usize {
-        nodes.into_iter().fold(0, |acc, child| {
-            self.assign_boundary_ref(parent, child);
-            acc + self.create(child)
-        })
+        nodes
+            .into_iter()
+            .map(|child| {
+                self.assign_boundary_ref(parent, child);
+                self.create(child)
+            })
+            .sum()
     }
 
     fn create_and_insert_before(

+ 3 - 0
packages/core/src/virtual_dom.rs

@@ -379,9 +379,11 @@ impl VirtualDom {
                 let template = unsafe { el_ref.unwrap().as_ref() };
                 let node_template = template.template.get();
                 let target_path = path.path;
+                println!("handle_event: {:?} ({:?})", target_path, template);
 
                 for (idx, attr) in template.dynamic_attrs.iter().enumerate() {
                     let this_path = node_template.attr_paths[idx];
+                    println!("checking: {:?} ({:?})", this_path, attr);
 
                     // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one
                     if attr.name.trim_start_matches("on") == name
@@ -401,6 +403,7 @@ impl VirtualDom {
                 // Now that we've accumulated all the parent attributes for the target element, call them in reverse order
                 // We check the bubble state between each call to see if the event has been stopped from bubbling
                 for listener in listeners.drain(..).rev() {
+                    println!("handle_event: {:?}", listener);
                     if let AttributeValue::Listener(listener) = listener {
                         let origin = path.scope;
                         self.runtime.scope_stack.borrow_mut().push(origin);

+ 1 - 0
packages/core/tests/event_propagation.rs

@@ -55,6 +55,7 @@ fn problematic_child(cx: Scope) -> Element {
     render! {
         button {
             onclick: move |evt| {
+                println!("bottom clicked");
                 let mut clicks = CLICKS.lock().unwrap();
 
                 if *clicks == 3 {