Forráskód Böngészése

feat: fake bubbling

Jonathan Kelley 3 éve
szülő
commit
11757ddf61

+ 1 - 0
packages/core/src/diff.rs

@@ -567,6 +567,7 @@ impl<'bump> DiffState<'bump> {
             return;
         }
 
+        self.scopes.update_reservation(new_node, root);
         new.dom_id.set(Some(root));
 
         // todo: attributes currently rely on the element on top of the stack, but in theory, we only need the id of the

+ 1 - 0
packages/core/src/scopearena.rs

@@ -369,6 +369,7 @@ impl ScopeArena {
         let mut cur_el = Some(element);
 
         while let Some(id) = cur_el.take() {
+            log::debug!("checking element {:?} for listeners", id);
             if let Some(el) = nodes.get(id.0) {
                 let real_el = unsafe { &**el };
                 if let VNode::Element(real_el) = real_el {

+ 17 - 17
packages/desktop/src/events.rs

@@ -39,69 +39,69 @@ pub fn trigger_from_serialized(val: serde_json::Value) -> UserEvent {
     }
 }
 
-fn make_synthetic_event(name: &str, val: serde_json::Value) -> Box<dyn Any + Send> {
+fn make_synthetic_event(name: &str, val: serde_json::Value) -> Arc<dyn Any + Send + Sync> {
     match name {
         "copy" | "cut" | "paste" => {
             //
-            Box::new(ClipboardEvent {})
+            Arc::new(ClipboardEvent {})
         }
         "compositionend" | "compositionstart" | "compositionupdate" => {
-            Box::new(serde_json::from_value::<CompositionEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<CompositionEvent>(val).unwrap())
         }
         "keydown" | "keypress" | "keyup" => {
             let evt = serde_json::from_value::<KeyboardEvent>(val).unwrap();
-            Box::new(evt)
+            Arc::new(evt)
         }
         "focus" | "blur" => {
             //
-            Box::new(FocusEvent {})
+            Arc::new(FocusEvent {})
         }
 
         // todo: these handlers might get really slow if the input box gets large and allocation pressure is heavy
         // don't have a good solution with the serialized event problem
         "change" | "input" | "invalid" | "reset" | "submit" => {
-            Box::new(serde_json::from_value::<FormEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<FormEvent>(val).unwrap())
         }
 
         "click" | "contextmenu" | "doubleclick" | "drag" | "dragend" | "dragenter" | "dragexit"
         | "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter"
         | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => {
-            Box::new(serde_json::from_value::<MouseEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<MouseEvent>(val).unwrap())
         }
         "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture"
         | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => {
-            Box::new(serde_json::from_value::<PointerEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<PointerEvent>(val).unwrap())
         }
         "select" => {
             //
-            Box::new(serde_json::from_value::<SelectionEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<SelectionEvent>(val).unwrap())
         }
 
         "touchcancel" | "touchend" | "touchmove" | "touchstart" => {
-            Box::new(serde_json::from_value::<TouchEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<TouchEvent>(val).unwrap())
         }
 
-        "scroll" => Box::new(()),
+        "scroll" => Arc::new(()),
 
-        "wheel" => Box::new(serde_json::from_value::<WheelEvent>(val).unwrap()),
+        "wheel" => Arc::new(serde_json::from_value::<WheelEvent>(val).unwrap()),
 
         "animationstart" | "animationend" | "animationiteration" => {
-            Box::new(serde_json::from_value::<AnimationEvent>(val).unwrap())
+            Arc::new(serde_json::from_value::<AnimationEvent>(val).unwrap())
         }
 
-        "transitionend" => Box::new(serde_json::from_value::<TransitionEvent>(val).unwrap()),
+        "transitionend" => Arc::new(serde_json::from_value::<TransitionEvent>(val).unwrap()),
 
         "abort" | "canplay" | "canplaythrough" | "durationchange" | "emptied" | "encrypted"
         | "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play"
         | "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend"
         | "timeupdate" | "volumechange" | "waiting" => {
             //
-            Box::new(MediaEvent {})
+            Arc::new(MediaEvent {})
         }
 
-        "toggle" => Box::new(ToggleEvent {}),
+        "toggle" => Arc::new(ToggleEvent {}),
 
-        _ => Box::new(()),
+        _ => Arc::new(()),
     }
 }
 

+ 2 - 2
packages/html/src/events.rs

@@ -24,7 +24,7 @@ pub mod on {
                         c: NodeFactory<'a>,
                         mut callback: F,
                     ) -> Listener<'a>
-                        where F: FnMut(&$wrapper) + 'a
+                        where F: FnMut(Arc<$wrapper>) + 'a
                     {
                         let bump = &c.bump();
 
@@ -32,7 +32,7 @@ pub mod on {
                         // safety: this is essentially the same as calling Box::new() but manually
                         // The box is attached to the lifetime of the bumpalo allocator
                         let cb: &mut dyn FnMut(Arc<dyn Any + Send + Sync>) = bump.alloc(move |evt: Arc<dyn Any + Send + Sync>| {
-                            let event = evt.downcast_ref::<$wrapper>().unwrap();
+                            let event = evt.downcast::<$wrapper>().unwrap();
                             callback(event)
                         });