allow nodes to depend on the listeners of a node
This commit is contained in:
1 parent
cebf17088b
commit
7b35566169
2 files changed
+15
No files matched your search
@@ -49,6 +49,10 @@ impl<'a> NodeView<'a> {
|
|||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn listeners(&self) -> &'a [Listener<'a>] {
|
||||||
|
self.el().map(|el| el.listeners).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
fn el(&self) -> Option<&'a VElement<'a>> {
|
fn el(&self) -> Option<&'a VElement<'a>> {
|
||||||
if let VNode::Element(el) = &self.inner {
|
if let VNode::Element(el) = &self.inner {
|
||||||
Some(el)
|
Some(el)
|
||||||
@@ -178,6 +182,7 @@ pub struct NodeMask {
|
|||||||
tag: bool,
|
tag: bool,
|
||||||
namespace: bool,
|
namespace: bool,
|
||||||
text: bool,
|
text: bool,
|
||||||
|
listeners: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeMask {
|
impl NodeMask {
|
||||||
@@ -191,6 +196,7 @@ impl NodeMask {
|
|||||||
|| (self.namespace && other.namespace)
|
|| (self.namespace && other.namespace)
|
||||||
|| self.attritutes.overlaps(&other.attritutes)
|
|| self.attritutes.overlaps(&other.attritutes)
|
||||||
|| (self.text && other.text)
|
|| (self.text && other.text)
|
||||||
|
|| (self.listeners && other.listeners)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn union(&self, other: &Self) -> Self {
|
pub fn union(&self, other: &Self) -> Self {
|
||||||
@@ -199,6 +205,7 @@ impl NodeMask {
|
|||||||
tag: self.tag | other.tag,
|
tag: self.tag | other.tag,
|
||||||
namespace: self.namespace | other.namespace,
|
namespace: self.namespace | other.namespace,
|
||||||
text: self.text | other.text,
|
text: self.text | other.text,
|
||||||
|
listeners: self.listeners | other.listeners,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +215,7 @@ impl NodeMask {
|
|||||||
tag: false,
|
tag: false,
|
||||||
namespace: false,
|
namespace: false,
|
||||||
text: false,
|
text: false,
|
||||||
|
listeners: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,4 +241,9 @@ impl NodeMask {
|
|||||||
self.text = true;
|
self.text = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn with_listeners(mut self) -> Self {
|
||||||
|
self.listeners = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -152,6 +152,7 @@ impl<S: State> RealDom<S> {
|
|||||||
scope: _,
|
scope: _,
|
||||||
root,
|
root,
|
||||||
} => {
|
} => {
|
||||||
|
nodes_updated.push((root as usize, NodeMask::new().with_listeners()));
|
||||||
if let Some(v) = self.nodes_listening.get_mut(event_name) {
|
if let Some(v) = self.nodes_listening.get_mut(event_name) {
|
||||||
v.insert(root as usize);
|
v.insert(root as usize);
|
||||||
} else {
|
} else {
|
||||||
@@ -161,6 +162,7 @@ impl<S: State> RealDom<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
RemoveEventListener { root, event } => {
|
RemoveEventListener { root, event } => {
|
||||||
|
nodes_updated.push((root as usize, NodeMask::new().with_listeners()));
|
||||||
let v = self.nodes_listening.get_mut(event).unwrap();
|
let v = self.nodes_listening.get_mut(event).unwrap();
|
||||||
v.remove(&(root as usize));
|
v.remove(&(root as usize));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user