more progress updating tui
This commit is contained in:
1 parent
8c07b4059f
commit
11b37ee141
11 files changed
+44
-64
No files matched your search
@@ -69,7 +69,6 @@ impl VirtualDom {
|
||||
)
|
||||
}
|
||||
|
||||
println!("reclaiming {:?}", el);
|
||||
self.elements.try_remove(el.0)
|
||||
}
|
||||
|
||||
@@ -95,9 +94,7 @@ impl VirtualDom {
|
||||
// Drop all the hooks once the children are dropped
|
||||
// this means we'll drop hooks bottom-up
|
||||
for hook in scope.hook_list.get_mut().drain(..) {
|
||||
println!("dropping hook !");
|
||||
drop(unsafe { BumpBox::from_raw(hook) });
|
||||
println!("hook dropped !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -388,11 +388,6 @@ impl<'b> VirtualDom {
|
||||
// Set the placeholder of the scope
|
||||
self.scopes[scope.0].placeholder.set(Some(new_id));
|
||||
|
||||
println!(
|
||||
"assigning id {:?} to path {:?}, template: {:?}",
|
||||
new_id, &template.template.node_paths, template.template
|
||||
);
|
||||
|
||||
// Since the placeholder is already in the DOM, we don't create any new nodes
|
||||
self.mutations.push(AssignId {
|
||||
id: new_id,
|
||||
|
||||
@@ -61,17 +61,10 @@ impl<'b> VirtualDom {
|
||||
}
|
||||
|
||||
fn diff_node(&mut self, left_template: &'b VNode<'b>, right_template: &'b VNode<'b>) {
|
||||
println!(
|
||||
"diffing node {:#?},\n\n{:#?}",
|
||||
left_template.template.name, right_template.template.name
|
||||
);
|
||||
|
||||
if left_template.template.name != right_template.template.name {
|
||||
return self.light_diff_templates(left_template, right_template);
|
||||
}
|
||||
|
||||
println!("diffing attributs...");
|
||||
|
||||
for (left_attr, right_attr) in left_template
|
||||
.dynamic_attrs
|
||||
.iter()
|
||||
@@ -106,8 +99,6 @@ impl<'b> VirtualDom {
|
||||
}
|
||||
}
|
||||
|
||||
println!("diffing dyn nodes...");
|
||||
|
||||
for (idx, (left_node, right_node)) in left_template
|
||||
.dynamic_nodes
|
||||
.iter()
|
||||
@@ -133,8 +124,6 @@ impl<'b> VirtualDom {
|
||||
};
|
||||
}
|
||||
|
||||
println!("applying roots...");
|
||||
|
||||
// Make sure the roots get transferred over
|
||||
for (left, right) in left_template
|
||||
.root_ids
|
||||
@@ -396,8 +385,6 @@ impl<'b> VirtualDom {
|
||||
"all siblings must be keyed or all siblings must be non-keyed"
|
||||
);
|
||||
|
||||
println!("Diffing fragment {:?}, {:?}", old.len(), new.len());
|
||||
|
||||
if new_is_keyed && old_is_keyed {
|
||||
self.diff_keyed_children(old, new);
|
||||
} else {
|
||||
@@ -420,8 +407,6 @@ impl<'b> VirtualDom {
|
||||
debug_assert!(!new.is_empty());
|
||||
debug_assert!(!old.is_empty());
|
||||
|
||||
println!("Diffing non keyed children");
|
||||
|
||||
match dbg!(old.len().cmp(&new.len())) {
|
||||
Ordering::Greater => self.remove_nodes(&old[new.len()..]),
|
||||
Ordering::Less => self.create_and_insert_after(&new[old.len()..], old.last().unwrap()),
|
||||
|
||||
@@ -40,8 +40,6 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
pub(crate) fn handle_suspense_wakeup(&mut self, id: SuspenseId) {
|
||||
println!("suspense notified");
|
||||
|
||||
let leaf = self
|
||||
.scheduler
|
||||
.leaves
|
||||
@@ -67,13 +65,6 @@ impl VirtualDom {
|
||||
// safety: we're not going to modify the suspense context but we don't want to make a clone of it
|
||||
let fiber = self.acquire_suspense_boundary(leaf.scope_id);
|
||||
|
||||
println!("ready pool");
|
||||
|
||||
println!(
|
||||
"Existing mutations {:?}, scope {:?}",
|
||||
fiber.mutations, fiber.id
|
||||
);
|
||||
|
||||
let scope = &mut self.scopes[scope_id.0];
|
||||
let arena = scope.current_frame();
|
||||
|
||||
@@ -106,16 +97,9 @@ impl VirtualDom {
|
||||
std::mem::swap(&mut self.mutations, mutations);
|
||||
|
||||
if fiber.waiting_on.borrow().is_empty() {
|
||||
println!("fiber is finished!");
|
||||
self.finished_fibers.push(fiber.id);
|
||||
} else {
|
||||
println!("fiber is not finished {:?}", fiber.waiting_on);
|
||||
}
|
||||
} else {
|
||||
println!("nodes arent right");
|
||||
}
|
||||
} else {
|
||||
println!("not ready");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -362,8 +362,6 @@ impl VirtualDom {
|
||||
let target_path = el_ref.path;
|
||||
|
||||
for (idx, attr) in template.dynamic_attrs.iter().enumerate() {
|
||||
println!("{:?} \n {:?} \n {:?}", attr, name, element);
|
||||
|
||||
let this_path = template.template.attr_paths[idx];
|
||||
|
||||
// listeners are required to be prefixed with "on", but they come back to the virtualdom with that missing
|
||||
@@ -385,8 +383,6 @@ impl VirtualDom {
|
||||
}
|
||||
}
|
||||
|
||||
println!("calling listeners: {:?}", listeners);
|
||||
|
||||
// Now that we've accumulated all the parent attributes for the target element, call them in reverse order
|
||||
// We check the bubble state between each call to see if the event has been stopped from bubbling
|
||||
for listener in listeners.drain(..).rev() {
|
||||
@@ -403,8 +399,6 @@ impl VirtualDom {
|
||||
|
||||
parent_path = template.parent.and_then(|id| self.elements.get(id.0));
|
||||
}
|
||||
|
||||
println!("all listeners exhausted");
|
||||
}
|
||||
|
||||
/// Wait for the scheduler to have any work.
|
||||
@@ -527,7 +521,6 @@ impl VirtualDom {
|
||||
///
|
||||
/// If no suspense trees are present
|
||||
pub async fn render_with_deadline(&mut self, deadline: impl Future<Output = ()>) -> Mutations {
|
||||
println!("render with deadline");
|
||||
pin_mut!(deadline);
|
||||
|
||||
loop {
|
||||
|
||||
@@ -3,6 +3,7 @@ use dioxus_core::ElementId;
|
||||
use crate::{
|
||||
node::{NodeData, NodeType, OwnedAttributeView},
|
||||
state::union_ordered_iter,
|
||||
RealNodeId,
|
||||
};
|
||||
|
||||
/// A view into a [VNode] with limited access.
|
||||
@@ -26,6 +27,11 @@ impl<'a> NodeView<'a> {
|
||||
self.inner.element_id
|
||||
}
|
||||
|
||||
/// Get the node id of the node
|
||||
pub fn node_id(&self) -> RealNodeId {
|
||||
self.inner.node_id
|
||||
}
|
||||
|
||||
/// Get the tag of the node if the tag is enabled in the mask
|
||||
pub fn tag(&self) -> Option<&'a str> {
|
||||
self.mask
|
||||
|
||||
@@ -334,7 +334,7 @@ pub fn resolve_passes<T, Tr: TreeView<T>>(
|
||||
if pass
|
||||
.dependancies()
|
||||
.iter()
|
||||
.all(|d| resolved_passes.contains(d))
|
||||
.all(|d| resolved_passes.contains(d) || *d == pass_id)
|
||||
&& !pass_mask.overlaps(currently_borrowed)
|
||||
{
|
||||
let pass = passes.remove(i);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use dioxus_core::{ElementId, Mutations, TemplateNode};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use std::fmt::Debug;
|
||||
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
||||
|
||||
use crate::node::{Node, NodeType, OwnedAttributeDiscription, OwnedAttributeValue};
|
||||
@@ -32,6 +33,7 @@ pub struct RealDom<S: State> {
|
||||
nodes_listening: FxHashMap<String, FxHashSet<RealNodeId>>,
|
||||
stack: Vec<RealNodeId>,
|
||||
templates: FxHashMap<String, Vec<RealNodeId>>,
|
||||
root_initialized: bool,
|
||||
}
|
||||
|
||||
impl<S: State> Default for RealDom<S> {
|
||||
@@ -55,10 +57,11 @@ impl<S: State> RealDom<S> {
|
||||
|
||||
RealDom {
|
||||
tree,
|
||||
node_id_mapping: Vec::new(),
|
||||
node_id_mapping: vec![Some(root_id)],
|
||||
nodes_listening: FxHashMap::default(),
|
||||
stack: vec![root_id],
|
||||
templates: FxHashMap::default(),
|
||||
root_initialized: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +102,7 @@ impl<S: State> RealDom<S> {
|
||||
&mut self,
|
||||
node: &TemplateNode,
|
||||
mutations_vec: &mut FxHashMap<RealNodeId, NodeMask>,
|
||||
) -> Option<RealNodeId> {
|
||||
) -> RealNodeId {
|
||||
match node {
|
||||
TemplateNode::Element {
|
||||
tag,
|
||||
@@ -132,21 +135,31 @@ impl<S: State> RealDom<S> {
|
||||
});
|
||||
let node_id = self.create_node(node);
|
||||
for child in *children {
|
||||
if let Some(child_id) = self.create_template_node(child, mutations_vec) {
|
||||
self.add_child(node_id, child_id);
|
||||
}
|
||||
let child_id = self.create_template_node(child, mutations_vec);
|
||||
self.add_child(node_id, child_id);
|
||||
}
|
||||
self.stack.push(node_id);
|
||||
Some(node_id)
|
||||
node_id
|
||||
}
|
||||
TemplateNode::Text(txt) => {
|
||||
let node_id = self.create_node(Node::new(NodeType::Text {
|
||||
text: txt.to_string(),
|
||||
}));
|
||||
self.stack.push(node_id);
|
||||
Some(node_id)
|
||||
node_id
|
||||
}
|
||||
TemplateNode::Dynamic(_) => {
|
||||
let node_id = self.create_node(Node::new(NodeType::Placeholder));
|
||||
self.stack.push(node_id);
|
||||
node_id
|
||||
}
|
||||
TemplateNode::DynamicText(_) => {
|
||||
let node_id = self.create_node(Node::new(NodeType::Text {
|
||||
text: String::new(),
|
||||
}));
|
||||
self.stack.push(node_id);
|
||||
node_id
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +169,17 @@ impl<S: State> RealDom<S> {
|
||||
for template in mutations.templates {
|
||||
let mut template_root_ids = Vec::new();
|
||||
for root in template.roots {
|
||||
if let Some(id) = self.create_template_node(root, &mut nodes_updated) {
|
||||
template_root_ids.push(id);
|
||||
}
|
||||
let id = self.create_template_node(root, &mut nodes_updated);
|
||||
template_root_ids.push(id);
|
||||
}
|
||||
self.templates
|
||||
.insert(template.name.to_string(), template_root_ids);
|
||||
}
|
||||
if !self.root_initialized {
|
||||
self.root_initialized = true;
|
||||
let root_id = self.tree.root();
|
||||
nodes_updated.insert(root_id, NodeMask::ALL);
|
||||
}
|
||||
for e in mutations.edits {
|
||||
use dioxus_core::Mutation::*;
|
||||
match e {
|
||||
@@ -171,7 +188,7 @@ impl<S: State> RealDom<S> {
|
||||
let parent = self.element_to_node_id(id);
|
||||
for child in children {
|
||||
self.add_child(parent, child);
|
||||
mark_dirty(parent, NodeMask::ALL, &mut nodes_updated);
|
||||
mark_dirty(child, NodeMask::ALL, &mut nodes_updated);
|
||||
}
|
||||
}
|
||||
AssignId { path, id } => {
|
||||
@@ -207,6 +224,7 @@ impl<S: State> RealDom<S> {
|
||||
let template_id = self.templates[name][index];
|
||||
let clone_id = self.clone_node(template_id, &mut nodes_updated);
|
||||
self.set_element_id(clone_id, id);
|
||||
self.stack.push(clone_id);
|
||||
}
|
||||
ReplaceWith { id, m } => {
|
||||
let new_nodes = self.stack.split_off(m);
|
||||
@@ -218,7 +236,7 @@ impl<S: State> RealDom<S> {
|
||||
self.tree.remove(old_node_id);
|
||||
}
|
||||
ReplacePlaceholder { path, m } => {
|
||||
let new_nodes = self.stack.split_off(m);
|
||||
let new_nodes = self.stack.split_off(self.stack.len() - m);
|
||||
let old_node_id = self.load_child(path);
|
||||
for new in new_nodes {
|
||||
self.tree.insert_after(old_node_id, new);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{node::NodeType, real_dom::RealDom, state::State, tree::TreeView, NodeId, RealNodeId};
|
||||
use dioxus_core::{Mutation, Mutations};
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub enum ElementProduced {
|
||||
/// The iterator produced an element by progressing to the next node in a depth first order.
|
||||
|
||||
@@ -17,7 +17,7 @@ impl<T> PossiblyUninitalized<T> {
|
||||
pub fn unwrap(self) -> T {
|
||||
match self {
|
||||
Self::Initialized(i) => i,
|
||||
_ => panic!(),
|
||||
_ => panic!("uninitalized"),
|
||||
}
|
||||
}
|
||||
pub fn ok(self) -> Option<T> {
|
||||
|
||||
@@ -16,7 +16,7 @@ use query::Query;
|
||||
use std::{cell::RefCell, sync::{Mutex, Arc}};
|
||||
use std::rc::Rc;
|
||||
use std::{io, time::Duration};
|
||||
use taffy::Taffy;
|
||||
use taffy::{Taffy};
|
||||
pub use taffy::{geometry::Point, prelude::*};
|
||||
use tui::{backend::CrosstermBackend, layout::Rect, Terminal};
|
||||
|
||||
@@ -168,12 +168,13 @@ fn render_vdom(
|
||||
if let Some(terminal) = &mut terminal {
|
||||
terminal.draw(|frame| {
|
||||
let rdom = rdom.borrow();
|
||||
let mut taffy =taffy.lock().expect("taffy lock poisoned");
|
||||
// size is guaranteed to not change when rendering
|
||||
resize(frame.size(), &mut taffy.lock().expect("taffy lock poisoned"), &rdom);
|
||||
resize(frame.size(), &mut *taffy, &rdom);
|
||||
let root = &rdom[NodeId(0)];
|
||||
render::render_vnode(
|
||||
frame,
|
||||
&taffy.lock().expect("taffy lock poisoned"),
|
||||
&*taffy,
|
||||
&rdom,
|
||||
root,
|
||||
cfg,
|
||||
|
||||
Reference in new issue
Block a user