clean up node api
This commit is contained in:
1 parent
0e7ee238ea
commit
0f6eb4fca2
4 files changed
+27
-27
No files matched your search
@@ -23,7 +23,7 @@ pub mod tree;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::node::{ElementNode, FromAnyValue, NodeType, OwnedAttributeView};
|
pub use crate::node::{ElementNode, FromAnyValue, NodeType, OwnedAttributeView, TextNode};
|
||||||
pub use crate::node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView};
|
pub use crate::node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView};
|
||||||
pub use crate::passes::{Dependancy, Pass};
|
pub use crate::passes::{Dependancy, Pass};
|
||||||
pub use crate::real_dom::{NodeImmutable, NodeMut, NodeRef, RealDom};
|
pub use crate::real_dom::{NodeImmutable, NodeMut, NodeRef, RealDom};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
use std::sync::{Arc, RwLock};
|
||||||
use std::sync::RwLock;
|
|
||||||
|
|
||||||
use crate::node::{
|
use crate::node::{
|
||||||
ElementNode, FromAnyValue, NodeType, OwnedAttributeDiscription, OwnedAttributeValue, TextNode,
|
ElementNode, FromAnyValue, NodeType, OwnedAttributeDiscription, OwnedAttributeValue, TextNode,
|
||||||
@@ -54,7 +53,7 @@ impl<V: FromAnyValue + Send + Sync> NodesDirty<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeWatchers<V> = Rc<RwLock<Vec<Box<dyn NodeWatcher<V>>>>>;
|
type NodeWatchers<V> = Arc<RwLock<Vec<Box<dyn NodeWatcher<V> + Send + Sync>>>>;
|
||||||
|
|
||||||
/// A Dom that can sync with the VirtualDom mutations intended for use in lazy renderers.
|
/// A Dom that can sync with the VirtualDom mutations intended for use in lazy renderers.
|
||||||
/// The render state passes from parent to children and or accumulates state from children to parents.
|
/// The render state passes from parent to children and or accumulates state from children to parents.
|
||||||
@@ -276,7 +275,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
|||||||
self.tree.insert_slab::<T>();
|
self.tree.insert_slab::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_node_watcher(&mut self, watcher: impl NodeWatcher<V> + 'static) {
|
pub fn add_node_watcher(&mut self, watcher: impl NodeWatcher<V> + 'static + Send + Sync) {
|
||||||
self.node_watchers.write().unwrap().push(Box::new(watcher));
|
self.node_watchers.write().unwrap().push(Box::new(watcher));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,15 +301,17 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn children(&self) -> Option<Vec<NodeRef<V>>> {
|
fn children(&self) -> Vec<NodeRef<V>> {
|
||||||
self.child_ids().map(|ids| {
|
self.child_ids()
|
||||||
ids.iter()
|
.map(|ids| {
|
||||||
.map(|id| NodeRef {
|
ids.iter()
|
||||||
id: *id,
|
.map(|id| NodeRef {
|
||||||
dom: self.real_dom(),
|
id: *id,
|
||||||
})
|
dom: self.real_dom(),
|
||||||
.collect()
|
})
|
||||||
})
|
.collect()
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -355,6 +356,11 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn height(&self) -> u16 {
|
||||||
|
self.real_dom().tree.height(self.id()).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NodeRef<'a, V: FromAnyValue + Send + Sync = ()> {
|
pub struct NodeRef<'a, V: FromAnyValue + Send + Sync = ()> {
|
||||||
|
|||||||
@@ -97,12 +97,10 @@ impl PersistantElementIter {
|
|||||||
if let Some(current) = stack.last().and_then(|last| rdom.get(*last)) {
|
if let Some(current) = stack.last().and_then(|last| rdom.get(*last)) {
|
||||||
// if the current element has children, add the first child to the stack and return it
|
// if the current element has children, add the first child to the stack and return it
|
||||||
if look_in_children {
|
if look_in_children {
|
||||||
if let Some(children) = current.children() {
|
if let Some(first) = current.children().first() {
|
||||||
if let Some(first) = children.first() {
|
let new = first.id();
|
||||||
let new = first.id();
|
stack.push(new);
|
||||||
stack.push(new);
|
return ElementProduced::Progressed(new);
|
||||||
return ElementProduced::Progressed(new);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack.pop();
|
stack.pop();
|
||||||
@@ -133,12 +131,8 @@ impl PersistantElementIter {
|
|||||||
node: NodeRef<V>,
|
node: NodeRef<V>,
|
||||||
) -> NodeId {
|
) -> NodeId {
|
||||||
stack.push(node.id());
|
stack.push(node.id());
|
||||||
if let Some(children) = node.children() {
|
if let Some(last) = node.children().last() {
|
||||||
if let Some(last) = children.last() {
|
push_back(stack, *last)
|
||||||
push_back(stack, *last)
|
|
||||||
} else {
|
|
||||||
node.id()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
node.id()
|
node.id()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ pub(crate) fn render_vnode(
|
|||||||
frame.render_widget(WidgetWithContext::new(node, cfg), area);
|
frame.render_widget(WidgetWithContext::new(node, cfg), area);
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in node.children().unwrap() {
|
for c in node.children() {
|
||||||
render_vnode(frame, layout, c, cfg, location);
|
render_vnode(frame, layout, c, cfg, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user