allow nodes to depend on the listeners of a node

This commit is contained in:
Evan Almloff committed 2022-04-21 15:10:53 -05:00
1 parent cebf17088b
commit 7b35566169
2 files changed
+15

No files matched your search

+13
View File
@@ -49,6 +49,10 @@ impl<'a> NodeView<'a> {
.flatten()
}
pub fn listeners(&self) -> &'a [Listener<'a>] {
self.el().map(|el| el.listeners).unwrap_or_default()
}
fn el(&self) -> Option<&'a VElement<'a>> {
if let VNode::Element(el) = &self.inner {
Some(el)
@@ -178,6 +182,7 @@ pub struct NodeMask {
tag: bool,
namespace: bool,
text: bool,
listeners: bool,
}
impl NodeMask {
@@ -191,6 +196,7 @@ impl NodeMask {
|| (self.namespace && other.namespace)
|| self.attritutes.overlaps(&other.attritutes)
|| (self.text && other.text)
|| (self.listeners && other.listeners)
}
pub fn union(&self, other: &Self) -> Self {
@@ -199,6 +205,7 @@ impl NodeMask {
tag: self.tag | other.tag,
namespace: self.namespace | other.namespace,
text: self.text | other.text,
listeners: self.listeners | other.listeners,
}
}
@@ -208,6 +215,7 @@ impl NodeMask {
tag: false,
namespace: false,
text: false,
listeners: false,
}
}
@@ -233,4 +241,9 @@ impl NodeMask {
self.text = true;
self
}
pub const fn with_listeners(mut self) -> Self {
self.listeners = true;
self
}
}
+2
View File
@@ -152,6 +152,7 @@ impl<S: State> RealDom<S> {
scope: _,
root,
} => {
nodes_updated.push((root as usize, NodeMask::new().with_listeners()));
if let Some(v) = self.nodes_listening.get_mut(event_name) {
v.insert(root as usize);
} else {
@@ -161,6 +162,7 @@ impl<S: State> RealDom<S> {
}
}
RemoveEventListener { root, event } => {
nodes_updated.push((root as usize, NodeMask::new().with_listeners()));
let v = self.nodes_listening.get_mut(event).unwrap();
v.remove(&(root as usize));
}