feat: events bubble now

This commit is contained in:
Jonathan Kelley committed 2021-11-11 22:07:38 -05:00
1 parent b6262edd53
commit f2234068ba
6 files changed
+63 -57

No files matched your search

+26 -1
View File
@@ -2,7 +2,10 @@ use bumpalo::Bump;
use futures_channel::mpsc::UnboundedSender;
use fxhash::FxHashMap;
use slab::Slab;
use std::cell::{Cell, RefCell};
use std::{
borrow::Borrow,
cell::{Cell, RefCell},
};
use crate::innerlude::*;
@@ -361,6 +364,28 @@ impl ScopeArena {
}
}
pub fn call_listener_with_bubbling(&self, event: UserEvent, element: ElementId) {
let nodes = self.nodes.borrow();
let mut cur_el = Some(element);
while let Some(id) = cur_el.take() {
if let Some(el) = nodes.get(id.0) {
let real_el = unsafe { &**el };
if let VNode::Element(real_el) = real_el {
for listener in real_el.listeners.borrow().iter() {
if listener.event == event.name {
let mut cb = listener.callback.borrow_mut();
if let Some(cb) = cb.as_mut() {
(cb)(event.event.clone());
}
}
}
cur_el = real_el.parent_id.get();
}
}
}
}
// The head of the bumpframe is the first linked NodeLink
pub fn wip_head(&self, id: &ScopeId) -> &VNode {
let scope = self.get_scope(id).unwrap();