feat: fake bubbling

This commit is contained in:
Jonathan Kelley committed 2021-11-11 22:18:16 -05:00
1 parent f2234068ba
commit 11757ddf61
4 files changed
+21 -19

No files matched your search

+1
View File
@@ -567,6 +567,7 @@ impl<'bump> DiffState<'bump> {
return; return;
} }
self.scopes.update_reservation(new_node, root);
new.dom_id.set(Some(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 // todo: attributes currently rely on the element on top of the stack, but in theory, we only need the id of the
+1
View File
@@ -369,6 +369,7 @@ impl ScopeArena {
let mut cur_el = Some(element); let mut cur_el = Some(element);
while let Some(id) = cur_el.take() { while let Some(id) = cur_el.take() {
log::debug!("checking element {:?} for listeners", id);
if let Some(el) = nodes.get(id.0) { if let Some(el) = nodes.get(id.0) {
let real_el = unsafe { &**el }; let real_el = unsafe { &**el };
if let VNode::Element(real_el) = real_el { if let VNode::Element(real_el) = real_el {
+17 -17
View File
@@ -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 { match name {
"copy" | "cut" | "paste" => { "copy" | "cut" | "paste" => {
// //
Box::new(ClipboardEvent {}) Arc::new(ClipboardEvent {})
} }
"compositionend" | "compositionstart" | "compositionupdate" => { "compositionend" | "compositionstart" | "compositionupdate" => {
Box::new(serde_json::from_value::<CompositionEvent>(val).unwrap()) Arc::new(serde_json::from_value::<CompositionEvent>(val).unwrap())
} }
"keydown" | "keypress" | "keyup" => { "keydown" | "keypress" | "keyup" => {
let evt = serde_json::from_value::<KeyboardEvent>(val).unwrap(); let evt = serde_json::from_value::<KeyboardEvent>(val).unwrap();
Box::new(evt) Arc::new(evt)
} }
"focus" | "blur" => { "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 // 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 // don't have a good solution with the serialized event problem
"change" | "input" | "invalid" | "reset" | "submit" => { "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" "click" | "contextmenu" | "doubleclick" | "drag" | "dragend" | "dragenter" | "dragexit"
| "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter" | "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter"
| "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => { | "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" "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture"
| "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => { | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => {
Box::new(serde_json::from_value::<PointerEvent>(val).unwrap()) Arc::new(serde_json::from_value::<PointerEvent>(val).unwrap())
} }
"select" => { "select" => {
// //
Box::new(serde_json::from_value::<SelectionEvent>(val).unwrap()) Arc::new(serde_json::from_value::<SelectionEvent>(val).unwrap())
} }
"touchcancel" | "touchend" | "touchmove" | "touchstart" => { "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" => { "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" "abort" | "canplay" | "canplaythrough" | "durationchange" | "emptied" | "encrypted"
| "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play" | "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play"
| "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend" | "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend"
| "timeupdate" | "volumechange" | "waiting" => { | "timeupdate" | "volumechange" | "waiting" => {
// //
Box::new(MediaEvent {}) Arc::new(MediaEvent {})
} }
"toggle" => Box::new(ToggleEvent {}), "toggle" => Arc::new(ToggleEvent {}),
_ => Box::new(()), _ => Arc::new(()),
} }
} }
+2 -2
View File
@@ -24,7 +24,7 @@ pub mod on {
c: NodeFactory<'a>, c: NodeFactory<'a>,
mut callback: F, mut callback: F,
) -> Listener<'a> ) -> Listener<'a>
where F: FnMut(&$wrapper) + 'a where F: FnMut(Arc<$wrapper>) + 'a
{ {
let bump = &c.bump(); let bump = &c.bump();
@@ -32,7 +32,7 @@ pub mod on {
// safety: this is essentially the same as calling Box::new() but manually // safety: this is essentially the same as calling Box::new() but manually
// The box is attached to the lifetime of the bumpalo allocator // 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 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) callback(event)
}); });