|
@@ -16,7 +16,7 @@ use crate::{
|
|
|
use rustc_hash::{FxHashMap, FxHashSet};
|
|
|
use DynamicNode::*;
|
|
|
|
|
|
-impl<'b> VirtualDom {
|
|
|
+impl VirtualDom {
|
|
|
pub(super) fn diff_scope(&mut self, scope: ScopeId) {
|
|
|
self.runtime.scope_stack.borrow_mut().push(scope);
|
|
|
let scope_state = &mut self.get_scope(scope).unwrap();
|
|
@@ -59,7 +59,7 @@ impl<'b> VirtualDom {
|
|
|
self.runtime.scope_stack.borrow_mut().pop();
|
|
|
}
|
|
|
|
|
|
- fn diff_ok_to_err(&mut self, l: &'b VNode, p: &'b VPlaceholder) {
|
|
|
+ fn diff_ok_to_err(&mut self, l: &VNode, p: &VPlaceholder) {
|
|
|
let id = self.next_element();
|
|
|
p.id.set(Some(id));
|
|
|
p.parent.set(l.parent.get());
|
|
@@ -82,7 +82,7 @@ impl<'b> VirtualDom {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- fn diff_node(&mut self, left_template: &'b VNode, right_template: &'b VNode) {
|
|
|
+ fn diff_node(&mut self, left_template: &VNode, right_template: &VNode) {
|
|
|
// If hot reloading is enabled, we need to make sure we're using the latest template
|
|
|
#[cfg(debug_assertions)]
|
|
|
{
|
|
@@ -166,8 +166,8 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
fn diff_dynamic_node(
|
|
|
&mut self,
|
|
|
- left_node: &'b DynamicNode<'b>,
|
|
|
- right_node: &'b DynamicNode<'b>,
|
|
|
+ left_node: &DynamicNode,
|
|
|
+ right_node: &DynamicNode,
|
|
|
parent: ElementRef,
|
|
|
) {
|
|
|
match (left_node, right_node) {
|
|
@@ -184,9 +184,9 @@ impl<'b> VirtualDom {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- fn update_attribute(&mut self, right_attr: &'b Attribute<'b>, left_attr: &'b Attribute) {
|
|
|
+ fn update_attribute(&mut self, right_attr: &Attribute, left_attr: &Attribute) {
|
|
|
let name = unsafe { std::mem::transmute(left_attr.name) };
|
|
|
- let value: BorrowedAttributeValue<'b> = (&right_attr.value).into();
|
|
|
+ let value: BorrowedAttributeValue = (&right_attr.value).into();
|
|
|
let value = unsafe { std::mem::transmute(value) };
|
|
|
self.mutations.push(Mutation::SetAttribute {
|
|
|
id: left_attr.mounted_element.get(),
|
|
@@ -198,8 +198,8 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
fn diff_vcomponent(
|
|
|
&mut self,
|
|
|
- left: &'b VComponent,
|
|
|
- right: &'b VComponent,
|
|
|
+ left: &VComponent,
|
|
|
+ right: &VComponent,
|
|
|
parent: Option<ElementRef>,
|
|
|
) {
|
|
|
if std::ptr::eq(left, right) {
|
|
@@ -249,8 +249,8 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
fn replace_vcomponent(
|
|
|
&mut self,
|
|
|
- right: &'b VComponent,
|
|
|
- left: &'b VComponent,
|
|
|
+ right: &VComponent,
|
|
|
+ left: &VComponent,
|
|
|
parent: Option<ElementRef>,
|
|
|
) {
|
|
|
let m = self.create_component_node(parent, right);
|
|
@@ -307,7 +307,7 @@ impl<'b> VirtualDom {
|
|
|
/// Component { ..props }
|
|
|
/// }
|
|
|
/// ```
|
|
|
- fn light_diff_templates(&mut self, left: &'b VNode, right: &'b VNode) {
|
|
|
+ fn light_diff_templates(&mut self, left: &VNode, right: &VNode) {
|
|
|
let parent = left.parent.take();
|
|
|
match matching_components(left, right) {
|
|
|
None => self.replace(left, [right], parent),
|
|
@@ -321,7 +321,7 @@ impl<'b> VirtualDom {
|
|
|
///
|
|
|
/// This just moves the ID of the old node over to the new node, and then sets the text of the new node if it's
|
|
|
/// different.
|
|
|
- fn diff_vtext(&mut self, left: &'b VText, right: &'b VText) {
|
|
|
+ fn diff_vtext(&mut self, left: &VText, right: &VText) {
|
|
|
let id = left.id.get().unwrap_or_else(|| self.next_element());
|
|
|
|
|
|
right.id.set(Some(id));
|
|
@@ -331,7 +331,7 @@ impl<'b> VirtualDom {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fn diff_non_empty_fragment(&mut self, old: &'b [VNode], new: &'b [VNode], parent: ElementRef) {
|
|
|
+ fn diff_non_empty_fragment(&mut self, old: &[VNode], new: &[VNode], parent: ElementRef) {
|
|
|
let new_is_keyed = new[0].key.is_some();
|
|
|
let old_is_keyed = old[0].key.is_some();
|
|
|
debug_assert!(
|
|
@@ -358,7 +358,7 @@ impl<'b> VirtualDom {
|
|
|
// [... parent]
|
|
|
//
|
|
|
// the change list stack is in the same state when this function returns.
|
|
|
- fn diff_non_keyed_children(&mut self, old: &'b [VNode], new: &'b [VNode], parent: ElementRef) {
|
|
|
+ fn diff_non_keyed_children(&mut self, old: &[VNode], new: &[VNode], parent: ElementRef) {
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
|
// Handled these cases in `diff_children` before calling this function.
|
|
@@ -394,10 +394,10 @@ impl<'b> VirtualDom {
|
|
|
// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
|
|
|
//
|
|
|
// The stack is empty upon entry.
|
|
|
- fn diff_keyed_children(&mut self, old: &'b [VNode], new: &'b [VNode], parent: ElementRef) {
|
|
|
+ fn diff_keyed_children(&mut self, old: &[VNode], new: &[VNode], parent: ElementRef) {
|
|
|
if cfg!(debug_assertions) {
|
|
|
let mut keys = rustc_hash::FxHashSet::default();
|
|
|
- let mut assert_unique_keys = |children: &'b [VNode]| {
|
|
|
+ let mut assert_unique_keys = |children: &[VNode]| {
|
|
|
keys.clear();
|
|
|
for child in children {
|
|
|
let key = child.key;
|
|
@@ -470,8 +470,8 @@ impl<'b> VirtualDom {
|
|
|
/// If there is no offset, then this function returns None and the diffing is complete.
|
|
|
fn diff_keyed_ends(
|
|
|
&mut self,
|
|
|
- old: &'b [VNode],
|
|
|
- new: &'b [VNode],
|
|
|
+ old: &[VNode],
|
|
|
+ new: &[VNode],
|
|
|
parent: ElementRef,
|
|
|
) -> Option<(usize, usize)> {
|
|
|
let mut left_offset = 0;
|
|
@@ -527,7 +527,7 @@ impl<'b> VirtualDom {
|
|
|
//
|
|
|
// Upon exit from this function, it will be restored to that same self.
|
|
|
#[allow(clippy::too_many_lines)]
|
|
|
- fn diff_keyed_middle(&mut self, old: &'b [VNode], new: &'b [VNode], parent: ElementRef) {
|
|
|
+ fn diff_keyed_middle(&mut self, old: &[VNode], new: &[VNode], parent: ElementRef) {
|
|
|
/*
|
|
|
1. Map the old keys into a numerical ordering based on indices.
|
|
|
2. Create a map of old key to its index
|
|
@@ -709,7 +709,7 @@ impl<'b> VirtualDom {
|
|
|
}
|
|
|
|
|
|
/// Push all the real nodes on the stack
|
|
|
- fn push_all_real_nodes(&mut self, node: &'b VNode) -> usize {
|
|
|
+ fn push_all_real_nodes(&mut self, node: &VNode) -> usize {
|
|
|
node.template
|
|
|
.get()
|
|
|
.roots
|
|
@@ -746,12 +746,7 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
Component(comp) => {
|
|
|
let scope = comp.scope.get().unwrap();
|
|
|
- match unsafe {
|
|
|
- self.get_scope(scope)
|
|
|
- .unwrap()
|
|
|
- .root_node()
|
|
|
- .extend_lifetime_ref()
|
|
|
- } {
|
|
|
+ match self.get_scope(scope).unwrap().root_node() {
|
|
|
RenderReturn::Ready(node) => self.push_all_real_nodes(node),
|
|
|
RenderReturn::Aborted(_node) => todo!(),
|
|
|
}
|
|
@@ -761,9 +756,9 @@ impl<'b> VirtualDom {
|
|
|
.sum()
|
|
|
}
|
|
|
|
|
|
- pub(crate) fn create_children(
|
|
|
+ pub(crate) fn create_children<'a>(
|
|
|
&mut self,
|
|
|
- nodes: impl IntoIterator<Item = &'b VNode>,
|
|
|
+ nodes: impl IntoIterator<Item = &'a VNode>,
|
|
|
parent: Option<ElementRef>,
|
|
|
) -> usize {
|
|
|
nodes
|
|
@@ -775,28 +770,23 @@ impl<'b> VirtualDom {
|
|
|
.sum()
|
|
|
}
|
|
|
|
|
|
- fn create_and_insert_before(
|
|
|
- &mut self,
|
|
|
- new: &'b [VNode],
|
|
|
- before: &'b VNode,
|
|
|
- parent: ElementRef,
|
|
|
- ) {
|
|
|
+ fn create_and_insert_before(&mut self, new: &[VNode], before: &VNode, parent: ElementRef) {
|
|
|
let m = self.create_children(new, Some(parent));
|
|
|
let id = self.find_first_element(before);
|
|
|
self.mutations.push(Mutation::InsertBefore { id, m })
|
|
|
}
|
|
|
|
|
|
- fn create_and_insert_after(&mut self, new: &'b [VNode], after: &'b VNode, parent: ElementRef) {
|
|
|
+ fn create_and_insert_after(&mut self, new: &[VNode], after: &VNode, parent: ElementRef) {
|
|
|
let m = self.create_children(new, Some(parent));
|
|
|
let id = self.find_last_element(after);
|
|
|
self.mutations.push(Mutation::InsertAfter { id, m })
|
|
|
}
|
|
|
|
|
|
/// Simply replace a placeholder with a list of nodes
|
|
|
- fn replace_placeholder(
|
|
|
+ fn replace_placeholder<'a>(
|
|
|
&mut self,
|
|
|
- l: &'b VPlaceholder,
|
|
|
- r: impl IntoIterator<Item = &'b VNode>,
|
|
|
+ l: &VPlaceholder,
|
|
|
+ r: impl IntoIterator<Item = &'a VNode>,
|
|
|
parent: ElementRef,
|
|
|
) {
|
|
|
let m = self.create_children(r, Some(parent));
|
|
@@ -805,10 +795,10 @@ impl<'b> VirtualDom {
|
|
|
self.reclaim(id);
|
|
|
}
|
|
|
|
|
|
- fn replace(
|
|
|
+ fn replace<'a>(
|
|
|
&mut self,
|
|
|
- left: &'b VNode,
|
|
|
- right: impl IntoIterator<Item = &'b VNode>,
|
|
|
+ left: &VNode,
|
|
|
+ right: impl IntoIterator<Item = &'a VNode>,
|
|
|
parent: Option<ElementRef>,
|
|
|
) {
|
|
|
let m = self.create_children(right, parent);
|
|
@@ -830,7 +820,7 @@ impl<'b> VirtualDom {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- fn node_to_placeholder(&mut self, l: &'b [VNode], r: &'b VPlaceholder, parent: ElementRef) {
|
|
|
+ fn node_to_placeholder(&mut self, l: &[VNode], r: &VPlaceholder, parent: ElementRef) {
|
|
|
// Create the placeholder first, ensuring we get a dedicated ID for the placeholder
|
|
|
let placeholder = self.next_element();
|
|
|
|
|
@@ -853,14 +843,14 @@ impl<'b> VirtualDom {
|
|
|
|
|
|
/// Remove these nodes from the dom
|
|
|
/// Wont generate mutations for the inner nodes
|
|
|
- fn remove_nodes(&mut self, nodes: &'b [VNode]) {
|
|
|
+ fn remove_nodes(&mut self, nodes: &[VNode]) {
|
|
|
nodes
|
|
|
.iter()
|
|
|
.rev()
|
|
|
.for_each(|node| self.remove_node(node, true));
|
|
|
}
|
|
|
|
|
|
- fn remove_node(&mut self, node: &'b VNode, gen_muts: bool) {
|
|
|
+ fn remove_node(&mut self, node: &VNode, gen_muts: bool) {
|
|
|
// Clean up any attributes that have claimed a static node as dynamic for mount/unmounta
|
|
|
// Will not generate mutations!
|
|
|
self.reclaim_attributes(node);
|
|
@@ -878,7 +868,7 @@ impl<'b> VirtualDom {
|
|
|
self.reclaim_vnode_id(node);
|
|
|
}
|
|
|
|
|
|
- fn reclaim_vnode_id(&mut self, node: &'b VNode) {
|
|
|
+ fn reclaim_vnode_id(&mut self, node: &VNode) {
|
|
|
// Clean up the vnode id
|
|
|
if let Some(id) = node.stable_id() {
|
|
|
self.element_refs.remove(id.0);
|
|
@@ -982,12 +972,7 @@ impl<'b> VirtualDom {
|
|
|
.expect("VComponents to always have a scope");
|
|
|
|
|
|
// Remove the component from the dom
|
|
|
- match unsafe {
|
|
|
- self.get_scope(scope)
|
|
|
- .unwrap()
|
|
|
- .root_node()
|
|
|
- .extend_lifetime_ref()
|
|
|
- } {
|
|
|
+ match unsafe { self.get_scope(scope).unwrap().root_node() } {
|
|
|
RenderReturn::Ready(t) => self.remove_node(t, gen_muts),
|
|
|
RenderReturn::Aborted(placeholder) => self.remove_placeholder(placeholder, gen_muts),
|
|
|
};
|
|
@@ -1000,7 +985,7 @@ impl<'b> VirtualDom {
|
|
|
self.drop_scope(scope, false);
|
|
|
}
|
|
|
|
|
|
- fn find_first_element(&self, node: &'b VNode) -> ElementId {
|
|
|
+ fn find_first_element(&self, node: &VNode) -> ElementId {
|
|
|
match node.dynamic_root(0) {
|
|
|
None => node.root_ids.borrow()[0],
|
|
|
Some(Text(t)) => t.id.get().unwrap(),
|
|
@@ -1008,12 +993,7 @@ impl<'b> VirtualDom {
|
|
|
Some(Placeholder(t)) => t.id.get().unwrap(),
|
|
|
Some(Component(comp)) => {
|
|
|
let scope = comp.scope.get().unwrap();
|
|
|
- match unsafe {
|
|
|
- self.get_scope(scope)
|
|
|
- .unwrap()
|
|
|
- .root_node()
|
|
|
- .extend_lifetime_ref()
|
|
|
- } {
|
|
|
+ match unsafe { self.get_scope(scope).unwrap().root_node() } {
|
|
|
RenderReturn::Ready(t) => self.find_first_element(t),
|
|
|
_ => todo!("cannot handle nonstandard nodes"),
|
|
|
}
|
|
@@ -1021,7 +1001,7 @@ impl<'b> VirtualDom {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fn find_last_element(&self, node: &'b VNode) -> ElementId {
|
|
|
+ fn find_last_element(&self, node: &VNode) -> ElementId {
|
|
|
match node.dynamic_root(node.template.get().roots.len() - 1) {
|
|
|
None => *node.root_ids.borrow().last().unwrap(),
|
|
|
Some(Text(t)) => t.id.get().unwrap(),
|
|
@@ -1029,12 +1009,7 @@ impl<'b> VirtualDom {
|
|
|
Some(Placeholder(t)) => t.id.get().unwrap(),
|
|
|
Some(Component(comp)) => {
|
|
|
let scope = comp.scope.get().unwrap();
|
|
|
- match unsafe {
|
|
|
- self.get_scope(scope)
|
|
|
- .unwrap()
|
|
|
- .root_node()
|
|
|
- .extend_lifetime_ref()
|
|
|
- } {
|
|
|
+ match unsafe { self.get_scope(scope).unwrap().root_node() } {
|
|
|
RenderReturn::Ready(t) => self.find_last_element(t),
|
|
|
_ => todo!("cannot handle nonstandard nodes"),
|
|
|
}
|
|
@@ -1042,7 +1017,7 @@ impl<'b> VirtualDom {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub(crate) fn assign_boundary_ref(&mut self, parent: Option<ElementRef>, child: &'b VNode) {
|
|
|
+ pub(crate) fn assign_boundary_ref(&mut self, parent: Option<ElementRef>, child: &VNode) {
|
|
|
if let Some(parent) = parent {
|
|
|
// assign the parent of the child
|
|
|
child.parent.set(Some(parent));
|
|
@@ -1055,7 +1030,7 @@ impl<'b> VirtualDom {
|
|
|
/// We need to check for the obvious case, and the non-obvious case where the template as cloned
|
|
|
///
|
|
|
/// We use the pointer of the dynamic_node list in this case
|
|
|
-fn templates_are_the_same<'b>(left_template: &'b VNode, right_template: &'b VNode) -> bool {
|
|
|
+fn templates_are_the_same(left_template: &VNode, right_template: &VNode) -> bool {
|
|
|
std::ptr::eq(left_template, right_template)
|
|
|
}
|
|
|
|