Merge branch 'master' into jk/coroutine-coroutineoverhaul

This commit is contained in:
Jonathan Kelley committed 2022-02-26 17:32:11 -05:00
commit 2b17717323
32 files changed
+860 -80

No files matched your search

+7 -16
View File
@@ -853,7 +853,7 @@ impl<'b> DiffState<'b> {
nodes_created += self.create_node(new_node);
} else {
self.diff_node(&old[old_index], new_node);
nodes_created += self.push_all_nodes(new_node);
nodes_created += self.push_all_real_nodes(new_node);
}
}
@@ -876,7 +876,7 @@ impl<'b> DiffState<'b> {
nodes_created += self.create_node(new_node);
} else {
self.diff_node(&old[old_index], new_node);
nodes_created += self.push_all_nodes(new_node);
nodes_created += self.push_all_real_nodes(new_node);
}
}
@@ -899,7 +899,7 @@ impl<'b> DiffState<'b> {
nodes_created += self.create_node(new_node);
} else {
self.diff_node(&old[old_index], new_node);
nodes_created += self.push_all_nodes(new_node);
nodes_created += self.push_all_real_nodes(new_node);
}
}
@@ -1100,9 +1100,9 @@ impl<'b> DiffState<'b> {
}
// recursively push all the nodes of a tree onto the stack and return how many are there
fn push_all_nodes(&mut self, node: &'b VNode<'b>) -> usize {
fn push_all_real_nodes(&mut self, node: &'b VNode<'b>) -> usize {
match node {
VNode::Text(_) | VNode::Placeholder(_) => {
VNode::Text(_) | VNode::Placeholder(_) | VNode::Element(_) => {
self.mutations.push_root(node.mounted_id());
1
}
@@ -1110,7 +1110,7 @@ impl<'b> DiffState<'b> {
VNode::Fragment(frag) => {
let mut added = 0;
for child in frag.children {
added += self.push_all_nodes(child);
added += self.push_all_real_nodes(child);
}
added
}
@@ -1118,16 +1118,7 @@ impl<'b> DiffState<'b> {
VNode::Component(c) => {
let scope_id = c.scope.get().unwrap();
let root = self.scopes.root_node(scope_id);
self.push_all_nodes(root)
}
VNode::Element(el) => {
let mut num_on_stack = 0;
for child in el.children.iter() {
num_on_stack += self.push_all_nodes(child);
}
self.mutations.push_root(el.id.get().unwrap());
num_on_stack + 1
self.push_all_real_nodes(root)
}
}
}
+10 -2
View File
@@ -107,6 +107,7 @@ pub enum DomEdit<'bump> {
RemoveAttribute {
root: u64,
name: &'static str,
ns: Option<&'bump str>,
},
}
@@ -218,8 +219,15 @@ impl<'a> Mutations<'a> {
}
pub(crate) fn remove_attribute(&mut self, attribute: &Attribute, root: u64) {
let name = attribute.name;
self.edits.push(RemoveAttribute { name, root });
let Attribute {
name, namespace, ..
} = attribute;
self.edits.push(RemoveAttribute {
name,
ns: *namespace,
root,
});
}
pub(crate) fn mark_dirty_scope(&mut self, scope: ScopeId) {
+14 -11
View File
@@ -11,6 +11,7 @@ use std::{
future::Future,
pin::Pin,
rc::Rc,
sync::Arc,
};
/// for traceability, we use the raw fn pointer to identify the function
@@ -96,11 +97,10 @@ impl ScopeArena {
// Get the height of the scope
let height = parent_scope
.map(|id| self.get_scope(id).map(|scope| scope.height + 1))
.flatten()
.and_then(|id| self.get_scope(id).map(|scope| scope.height + 1))
.unwrap_or_default();
let parent_scope = parent_scope.map(|f| self.get_scope_raw(f)).flatten();
let parent_scope = parent_scope.and_then(|f| self.get_scope_raw(f));
/*
This scopearena aggressively reuses old scopes when possible.
@@ -579,12 +579,17 @@ impl ScopeState {
self.our_arena_idx
}
/// Get a handle to the raw update scheduler channel
pub fn scheduler_channel(&self) -> UnboundedSender<SchedulerMsg> {
self.tasks.sender.clone()
}
/// Create a subscription that schedules a future render for the reference component
///
/// ## Notice: you should prefer using prepare_update and get_scope_id
pub fn schedule_update(&self) -> Rc<dyn Fn() + 'static> {
pub fn schedule_update(&self) -> Arc<dyn Fn() + Send + Sync + 'static> {
let (chan, id) = (self.tasks.sender.clone(), self.scope_id());
Rc::new(move || {
Arc::new(move || {
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
})
}
@@ -594,9 +599,9 @@ impl ScopeState {
/// A component's ScopeId can be obtained from `use_hook` or the [`ScopeState::scope_id`] method.
///
/// This method should be used when you want to schedule an update for a component
pub fn schedule_update_any(&self) -> Rc<dyn Fn(ScopeId)> {
pub fn schedule_update_any(&self) -> Arc<dyn Fn(ScopeId) + Send + Sync> {
let chan = self.tasks.sender.clone();
Rc::new(move |id| {
Arc::new(move |id| {
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
})
}
@@ -653,8 +658,7 @@ impl ScopeState {
self.shared_contexts
.borrow_mut()
.insert(TypeId::of::<T>(), value.clone())
.map(|f| f.downcast::<T>().ok())
.flatten();
.and_then(|f| f.downcast::<T>().ok());
value
}
@@ -684,8 +688,7 @@ impl ScopeState {
self.shared_contexts
.borrow_mut()
.insert(TypeId::of::<T>(), value.clone())
.map(|f| f.downcast::<T>().ok())
.flatten();
.and_then(|f| f.downcast::<T>().ok());
return value;
}