|
@@ -90,6 +90,7 @@
|
|
|
|
|
|
use crate::innerlude::*;
|
|
use crate::innerlude::*;
|
|
use fxhash::{FxHashMap, FxHashSet};
|
|
use fxhash::{FxHashMap, FxHashSet};
|
|
|
|
+use slab::Slab;
|
|
use DomEdit::*;
|
|
use DomEdit::*;
|
|
|
|
|
|
/// Our DiffMachine is an iterative tree differ.
|
|
/// Our DiffMachine is an iterative tree differ.
|
|
@@ -104,76 +105,33 @@ use DomEdit::*;
|
|
///
|
|
///
|
|
/// Funnily enough, this stack machine's entire job is to create instructions for another stack machine to execute. It's
|
|
/// Funnily enough, this stack machine's entire job is to create instructions for another stack machine to execute. It's
|
|
/// stack machines all the way down!
|
|
/// stack machines all the way down!
|
|
-pub(crate) struct DiffMachine<'bump> {
|
|
|
|
- pub vdom: &'bump ResourcePool,
|
|
|
|
|
|
+pub struct DiffState<'bump> {
|
|
pub mutations: Mutations<'bump>,
|
|
pub mutations: Mutations<'bump>,
|
|
- pub stack: DiffStack<'bump>,
|
|
|
|
|
|
+ pub(crate) stack: DiffStack<'bump>,
|
|
pub seen_scopes: FxHashSet<ScopeId>,
|
|
pub seen_scopes: FxHashSet<ScopeId>,
|
|
- pub cfg: DiffCfg,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-pub(crate) struct DiffCfg {
|
|
|
|
pub force_diff: bool,
|
|
pub force_diff: bool,
|
|
}
|
|
}
|
|
-impl Default for DiffCfg {
|
|
|
|
- fn default() -> Self {
|
|
|
|
- Self {
|
|
|
|
- force_diff: Default::default(),
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
-/// a "saved" form of a diff machine
|
|
|
|
-/// in regular diff machine, the &'bump reference is a stack borrow, but the
|
|
|
|
-/// bump lifetimes are heap borrows.
|
|
|
|
-pub(crate) struct SavedDiffWork<'bump> {
|
|
|
|
- pub mutations: Mutations<'bump>,
|
|
|
|
- pub stack: DiffStack<'bump>,
|
|
|
|
- pub seen_scopes: FxHashSet<ScopeId>,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl<'a> SavedDiffWork<'a> {
|
|
|
|
- pub unsafe fn extend(self: SavedDiffWork<'a>) -> SavedDiffWork<'static> {
|
|
|
|
- std::mem::transmute(self)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- pub unsafe fn promote<'b>(self, vdom: &'b ResourcePool) -> DiffMachine<'b> {
|
|
|
|
- let extended: SavedDiffWork<'b> = std::mem::transmute(self);
|
|
|
|
- DiffMachine {
|
|
|
|
- vdom,
|
|
|
|
- cfg: DiffCfg::default(),
|
|
|
|
- mutations: extended.mutations,
|
|
|
|
- stack: extended.stack,
|
|
|
|
- seen_scopes: extended.seen_scopes,
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl<'bump> DiffMachine<'bump> {
|
|
|
|
- pub(crate) fn new(mutations: Mutations<'bump>, shared: &'bump ResourcePool) -> Self {
|
|
|
|
|
|
+impl<'bump> DiffState<'bump> {
|
|
|
|
+ pub(crate) fn new(mutations: Mutations<'bump>) -> Self {
|
|
Self {
|
|
Self {
|
|
mutations,
|
|
mutations,
|
|
- cfg: DiffCfg::default(),
|
|
|
|
stack: DiffStack::new(),
|
|
stack: DiffStack::new(),
|
|
- vdom: shared,
|
|
|
|
- seen_scopes: FxHashSet::default(),
|
|
|
|
|
|
+ seen_scopes: Default::default(),
|
|
|
|
+ force_diff: false,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- pub fn save(self) -> SavedDiffWork<'bump> {
|
|
|
|
- SavedDiffWork {
|
|
|
|
- mutations: self.mutations,
|
|
|
|
- stack: self.stack,
|
|
|
|
- seen_scopes: self.seen_scopes,
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+impl<'bump> ScopeArena {
|
|
|
|
+ pub fn diff_scope(&'bump self, state: &mut DiffState<'bump>, id: &ScopeId) {
|
|
|
|
+ // if let Some(component) = self.get_scope(id) {
|
|
|
|
|
|
- pub fn diff_scope(&mut self, id: ScopeId) {
|
|
|
|
- if let Some(component) = self.vdom.get_scope_mut(id) {
|
|
|
|
- let (old, new) = (component.frames.wip_head(), component.frames.fin_head());
|
|
|
|
- self.stack.push(DiffInstruction::Diff { new, old });
|
|
|
|
- self.work(|| false);
|
|
|
|
- }
|
|
|
|
|
|
+ let (old, new) = (self.wip_head(id), self.fin_head(id));
|
|
|
|
+
|
|
|
|
+ state.stack.push(DiffInstruction::Diff { old, new });
|
|
|
|
+ self.work(state, || false);
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
|
|
|
|
/// Progress the diffing for this "fiber"
|
|
/// Progress the diffing for this "fiber"
|
|
@@ -183,14 +141,21 @@ impl<'bump> DiffMachine<'bump> {
|
|
/// We do depth-first to maintain high cache locality (nodes were originally generated recursively).
|
|
/// We do depth-first to maintain high cache locality (nodes were originally generated recursively).
|
|
///
|
|
///
|
|
/// Returns a `bool` indicating that the work completed properly.
|
|
/// Returns a `bool` indicating that the work completed properly.
|
|
- pub fn work(&mut self, mut deadline_expired: impl FnMut() -> bool) -> bool {
|
|
|
|
- while let Some(instruction) = self.stack.pop() {
|
|
|
|
|
|
+ pub fn work(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ mut deadline_expired: impl FnMut() -> bool,
|
|
|
|
+ ) -> bool {
|
|
|
|
+ while let Some(instruction) = state.stack.pop() {
|
|
match instruction {
|
|
match instruction {
|
|
- DiffInstruction::Diff { old, new } => self.diff_node(old, new),
|
|
|
|
- DiffInstruction::Create { node } => self.create_node(node),
|
|
|
|
- DiffInstruction::Mount { and } => self.mount(and),
|
|
|
|
- DiffInstruction::PrepareMove { node } => self.prepare_move_node(node),
|
|
|
|
- DiffInstruction::PopScope => self.stack.pop_off_scope(),
|
|
|
|
|
|
+ DiffInstruction::Diff { old, new } => self.diff_node(state, old, new),
|
|
|
|
+ DiffInstruction::Create { node } => self.create_node(state, node),
|
|
|
|
+ DiffInstruction::Mount { and } => self.mount(state, and),
|
|
|
|
+ DiffInstruction::PrepareMove { node } => {
|
|
|
|
+ let num_on_stack = self.push_all_nodes(state, node);
|
|
|
|
+ state.stack.add_child_count(num_on_stack);
|
|
|
|
+ }
|
|
|
|
+ DiffInstruction::PopScope => state.stack.pop_off_scope(),
|
|
};
|
|
};
|
|
|
|
|
|
if deadline_expired() {
|
|
if deadline_expired() {
|
|
@@ -202,48 +167,84 @@ impl<'bump> DiffMachine<'bump> {
|
|
true
|
|
true
|
|
}
|
|
}
|
|
|
|
|
|
- fn prepare_move_node(&mut self, node: &'bump VNode<'bump>) {
|
|
|
|
- for el in RealChildIterator::new(node, self.vdom) {
|
|
|
|
- self.mutations.push_root(el.mounted_id());
|
|
|
|
- self.stack.add_child_count(1);
|
|
|
|
|
|
+ // recursively push all the nodes of a tree onto the stack and return how many are there
|
|
|
|
+ fn push_all_nodes(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ node: &'bump VNode<'bump>,
|
|
|
|
+ ) -> usize {
|
|
|
|
+ match node {
|
|
|
|
+ VNode::Text(_) | VNode::Anchor(_) | VNode::Suspended(_) => {
|
|
|
|
+ state.mutations.push_root(node.mounted_id());
|
|
|
|
+ 1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ VNode::Linked(linked) => {
|
|
|
|
+ todo!("load linked");
|
|
|
|
+ 0
|
|
|
|
+ // let num_on_stack = linked.children.iter().map(|child| {
|
|
|
|
+ // self.push_all_nodes(state, child)
|
|
|
|
+ // }).sum();
|
|
|
|
+ // state.mutations.push_root(node.mounted_id());
|
|
|
|
+ // num_on_stack + 1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ VNode::Fragment(_) | VNode::Component(_) => {
|
|
|
|
+ //
|
|
|
|
+ let mut added = 0;
|
|
|
|
+ for child in node.children() {
|
|
|
|
+ added += self.push_all_nodes(state, child);
|
|
|
|
+ }
|
|
|
|
+ added
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ VNode::Element(el) => {
|
|
|
|
+ let mut num_on_stack = 0;
|
|
|
|
+ for child in el.children.iter() {
|
|
|
|
+ num_on_stack += self.push_all_nodes(state, child);
|
|
|
|
+ }
|
|
|
|
+ state.mutations.push_root(el.dom_id.get().unwrap());
|
|
|
|
+
|
|
|
|
+ num_on_stack + 1
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn mount(&mut self, and: MountType<'bump>) {
|
|
|
|
- let nodes_created = self.stack.pop_nodes_created();
|
|
|
|
|
|
+ fn mount(&'bump self, state: &mut DiffState<'bump>, and: MountType<'bump>) {
|
|
|
|
+ let nodes_created = state.stack.pop_nodes_created();
|
|
match and {
|
|
match and {
|
|
// add the nodes from this virtual list to the parent
|
|
// add the nodes from this virtual list to the parent
|
|
// used by fragments and components
|
|
// used by fragments and components
|
|
MountType::Absorb => {
|
|
MountType::Absorb => {
|
|
- self.stack.add_child_count(nodes_created);
|
|
|
|
|
|
+ state.stack.add_child_count(nodes_created);
|
|
}
|
|
}
|
|
|
|
|
|
MountType::Replace { old } => {
|
|
MountType::Replace { old } => {
|
|
if let Some(old_id) = old.try_mounted_id() {
|
|
if let Some(old_id) = old.try_mounted_id() {
|
|
- self.mutations.replace_with(old_id, nodes_created as u32);
|
|
|
|
- self.remove_nodes(Some(old), true);
|
|
|
|
|
|
+ state.mutations.replace_with(old_id, nodes_created as u32);
|
|
|
|
+ self.remove_nodes(state, Some(old), true);
|
|
} else {
|
|
} else {
|
|
if let Some(id) = self.find_first_element_id(old) {
|
|
if let Some(id) = self.find_first_element_id(old) {
|
|
- self.mutations.replace_with(id, nodes_created as u32);
|
|
|
|
|
|
+ state.mutations.replace_with(id, nodes_created as u32);
|
|
}
|
|
}
|
|
- self.remove_nodes(Some(old), true);
|
|
|
|
|
|
+ self.remove_nodes(state, Some(old), true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
MountType::Append => {
|
|
MountType::Append => {
|
|
- self.mutations.edits.push(AppendChildren {
|
|
|
|
|
|
+ state.mutations.edits.push(AppendChildren {
|
|
many: nodes_created as u32,
|
|
many: nodes_created as u32,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
MountType::InsertAfter { other_node } => {
|
|
MountType::InsertAfter { other_node } => {
|
|
let root = self.find_last_element(other_node).unwrap();
|
|
let root = self.find_last_element(other_node).unwrap();
|
|
- self.mutations.insert_after(root, nodes_created as u32);
|
|
|
|
|
|
+ state.mutations.insert_after(root, nodes_created as u32);
|
|
}
|
|
}
|
|
|
|
|
|
MountType::InsertBefore { other_node } => {
|
|
MountType::InsertBefore { other_node } => {
|
|
let root = self.find_first_element_id(other_node).unwrap();
|
|
let root = self.find_first_element_id(other_node).unwrap();
|
|
- self.mutations.insert_before(root, nodes_created as u32);
|
|
|
|
|
|
+ state.mutations.insert_before(root, nodes_created as u32);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -252,42 +253,63 @@ impl<'bump> DiffMachine<'bump> {
|
|
// Tools for creating new nodes
|
|
// Tools for creating new nodes
|
|
// =================================
|
|
// =================================
|
|
|
|
|
|
- fn create_node(&mut self, node: &'bump VNode<'bump>) {
|
|
|
|
|
|
+ fn create_node(&'bump self, state: &mut DiffState<'bump>, node: &'bump VNode<'bump>) {
|
|
match node {
|
|
match node {
|
|
- VNode::Text(vtext) => self.create_text_node(vtext, node),
|
|
|
|
- VNode::Suspended(suspended) => self.create_suspended_node(suspended, node),
|
|
|
|
- VNode::Anchor(anchor) => self.create_anchor_node(anchor, node),
|
|
|
|
- VNode::Element(element) => self.create_element_node(element, node),
|
|
|
|
- VNode::Fragment(frag) => self.create_fragment_node(frag),
|
|
|
|
- VNode::Component(component) => self.create_component_node(component),
|
|
|
|
|
|
+ VNode::Text(vtext) => self.create_text_node(state, vtext, node),
|
|
|
|
+ VNode::Suspended(suspended) => self.create_suspended_node(state, suspended, node),
|
|
|
|
+ VNode::Anchor(anchor) => self.create_anchor_node(state, anchor, node),
|
|
|
|
+ VNode::Element(element) => self.create_element_node(state, element, node),
|
|
|
|
+ VNode::Fragment(frag) => self.create_fragment_node(state, frag),
|
|
|
|
+ VNode::Component(component) => self.create_component_node(state, component),
|
|
|
|
+ VNode::Linked(linked) => self.create_linked_node(state, linked),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_text_node(&mut self, vtext: &'bump VText<'bump>, node: &'bump VNode<'bump>) {
|
|
|
|
- let real_id = self.vdom.reserve_node(node);
|
|
|
|
- self.mutations.create_text_node(vtext.text, real_id);
|
|
|
|
|
|
+ fn create_text_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ vtext: &'bump VText<'bump>,
|
|
|
|
+ node: &'bump VNode<'bump>,
|
|
|
|
+ ) {
|
|
|
|
+ let real_id = self.reserve_node(node);
|
|
|
|
+ state.mutations.create_text_node(vtext.text, real_id);
|
|
vtext.dom_id.set(Some(real_id));
|
|
vtext.dom_id.set(Some(real_id));
|
|
- self.stack.add_child_count(1);
|
|
|
|
|
|
+ state.stack.add_child_count(1);
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_suspended_node(&mut self, suspended: &'bump VSuspended, node: &'bump VNode<'bump>) {
|
|
|
|
- let real_id = self.vdom.reserve_node(node);
|
|
|
|
- self.mutations.create_placeholder(real_id);
|
|
|
|
|
|
+ fn create_suspended_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ suspended: &'bump VSuspended,
|
|
|
|
+ node: &'bump VNode<'bump>,
|
|
|
|
+ ) {
|
|
|
|
+ let real_id = self.reserve_node(node);
|
|
|
|
+ state.mutations.create_placeholder(real_id);
|
|
|
|
|
|
suspended.dom_id.set(Some(real_id));
|
|
suspended.dom_id.set(Some(real_id));
|
|
- self.stack.add_child_count(1);
|
|
|
|
|
|
+ state.stack.add_child_count(1);
|
|
|
|
|
|
- self.attach_suspended_node_to_scope(suspended);
|
|
|
|
|
|
+ self.attach_suspended_node_to_scope(state, suspended);
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_anchor_node(&mut self, anchor: &'bump VAnchor, node: &'bump VNode<'bump>) {
|
|
|
|
- let real_id = self.vdom.reserve_node(node);
|
|
|
|
- self.mutations.create_placeholder(real_id);
|
|
|
|
|
|
+ fn create_anchor_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ anchor: &'bump VAnchor,
|
|
|
|
+ node: &'bump VNode<'bump>,
|
|
|
|
+ ) {
|
|
|
|
+ let real_id = self.reserve_node(node);
|
|
|
|
+ state.mutations.create_placeholder(real_id);
|
|
anchor.dom_id.set(Some(real_id));
|
|
anchor.dom_id.set(Some(real_id));
|
|
- self.stack.add_child_count(1);
|
|
|
|
|
|
+ state.stack.add_child_count(1);
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_element_node(&mut self, element: &'bump VElement<'bump>, node: &'bump VNode<'bump>) {
|
|
|
|
|
|
+ fn create_element_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ element: &'bump VElement<'bump>,
|
|
|
|
+ node: &'bump VNode<'bump>,
|
|
|
|
+ ) {
|
|
let VElement {
|
|
let VElement {
|
|
tag_name,
|
|
tag_name,
|
|
listeners,
|
|
listeners,
|
|
@@ -298,75 +320,90 @@ impl<'bump> DiffMachine<'bump> {
|
|
..
|
|
..
|
|
} = element;
|
|
} = element;
|
|
|
|
|
|
- let real_id = self.vdom.reserve_node(node);
|
|
|
|
|
|
+ let real_id = self.reserve_node(node);
|
|
|
|
|
|
dom_id.set(Some(real_id));
|
|
dom_id.set(Some(real_id));
|
|
|
|
|
|
- self.mutations.create_element(tag_name, *namespace, real_id);
|
|
|
|
|
|
+ state
|
|
|
|
+ .mutations
|
|
|
|
+ .create_element(tag_name, *namespace, real_id);
|
|
|
|
|
|
- self.stack.add_child_count(1);
|
|
|
|
|
|
+ state.stack.add_child_count(1);
|
|
|
|
|
|
- if let Some(cur_scope_id) = self.stack.current_scope() {
|
|
|
|
- let scope = self.vdom.get_scope(cur_scope_id).unwrap();
|
|
|
|
|
|
+ if let Some(cur_scope_id) = state.stack.current_scope() {
|
|
|
|
+ let scope = self.get_scope(&cur_scope_id).unwrap();
|
|
|
|
|
|
- listeners.iter().for_each(|listener| {
|
|
|
|
|
|
+ for listener in *listeners {
|
|
self.attach_listener_to_scope(listener, scope);
|
|
self.attach_listener_to_scope(listener, scope);
|
|
listener.mounted_node.set(Some(real_id));
|
|
listener.mounted_node.set(Some(real_id));
|
|
- self.mutations.new_event_listener(listener, cur_scope_id);
|
|
|
|
- });
|
|
|
|
|
|
+ state.mutations.new_event_listener(listener, cur_scope_id);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
log::warn!("create element called with no scope on the stack - this is an error for a live dom");
|
|
log::warn!("create element called with no scope on the stack - this is an error for a live dom");
|
|
}
|
|
}
|
|
|
|
|
|
for attr in *attributes {
|
|
for attr in *attributes {
|
|
- self.mutations.set_attribute(attr, real_id.as_u64());
|
|
|
|
|
|
+ state.mutations.set_attribute(attr, real_id.as_u64());
|
|
}
|
|
}
|
|
|
|
|
|
if !children.is_empty() {
|
|
if !children.is_empty() {
|
|
- self.stack.create_children(children, MountType::Append);
|
|
|
|
|
|
+ state.stack.create_children(children, MountType::Append);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_fragment_node(&mut self, frag: &'bump VFragment<'bump>) {
|
|
|
|
- self.stack.create_children(frag.children, MountType::Absorb);
|
|
|
|
|
|
+ fn create_fragment_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ frag: &'bump VFragment<'bump>,
|
|
|
|
+ ) {
|
|
|
|
+ state
|
|
|
|
+ .stack
|
|
|
|
+ .create_children(frag.children, MountType::Absorb);
|
|
}
|
|
}
|
|
|
|
|
|
- fn create_component_node(&mut self, vcomponent: &'bump VComponent<'bump>) {
|
|
|
|
- let caller = vcomponent.caller;
|
|
|
|
|
|
+ fn create_component_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ vcomponent: &'bump VComponent<'bump>,
|
|
|
|
+ ) {
|
|
|
|
+ // let caller = vcomponent.caller;
|
|
|
|
|
|
- let parent_idx = self.stack.current_scope().unwrap();
|
|
|
|
|
|
+ let parent_idx = state.stack.current_scope().unwrap();
|
|
|
|
|
|
- let shared = self.vdom.channel.clone();
|
|
|
|
|
|
+ let shared = self.sender.clone();
|
|
|
|
|
|
// Insert a new scope into our component list
|
|
// Insert a new scope into our component list
|
|
- let parent_scope = self.vdom.get_scope(parent_idx).unwrap();
|
|
|
|
-
|
|
|
|
- let new_idx = self.vdom.insert_scope_with_key(|new_idx| {
|
|
|
|
- ScopeInner::new(
|
|
|
|
- caller,
|
|
|
|
- new_idx,
|
|
|
|
- Some(parent_idx),
|
|
|
|
- parent_scope.height + 1,
|
|
|
|
- parent_scope.subtree(),
|
|
|
|
- shared,
|
|
|
|
- )
|
|
|
|
- });
|
|
|
|
|
|
+ let parent_scope = self.get_scope(&parent_idx).unwrap();
|
|
|
|
+
|
|
|
|
+ let new_idx: ScopeId = todo!();
|
|
|
|
+ // self
|
|
|
|
+ // .new_with_key(fc_ptr, vcomp, parent_scope, height, subtree, sender);
|
|
|
|
+
|
|
|
|
+ // .(|new_idx| {
|
|
|
|
+ // // ScopeInner::new(
|
|
|
|
+ // vcomponent,
|
|
|
|
+ // new_idx,
|
|
|
|
+ // Some(parent_idx),
|
|
|
|
+ // parent_scope.height + 1,
|
|
|
|
+ // parent_scope.subtree(),
|
|
|
|
+ // shared,
|
|
|
|
+ // // )
|
|
|
|
+ // });
|
|
|
|
|
|
// Actually initialize the caller's slot with the right address
|
|
// Actually initialize the caller's slot with the right address
|
|
vcomponent.associated_scope.set(Some(new_idx));
|
|
vcomponent.associated_scope.set(Some(new_idx));
|
|
|
|
|
|
if !vcomponent.can_memoize {
|
|
if !vcomponent.can_memoize {
|
|
- let cur_scope = self.vdom.get_scope_mut(parent_idx).unwrap();
|
|
|
|
- let extended = vcomponent as *const VComponent;
|
|
|
|
- let extended: *const VComponent<'static> = unsafe { std::mem::transmute(extended) };
|
|
|
|
- cur_scope.borrowed_props.borrow_mut().push(extended);
|
|
|
|
|
|
+ let cur_scope = self.get_scope(&parent_idx).unwrap();
|
|
|
|
+ let extended = unsafe { std::mem::transmute(vcomponent) };
|
|
|
|
+ cur_scope.items.get_mut().borrowed_props.push(extended);
|
|
}
|
|
}
|
|
|
|
|
|
// TODO:
|
|
// TODO:
|
|
// add noderefs to current noderef list Noderefs
|
|
// add noderefs to current noderef list Noderefs
|
|
// add effects to current effect list Effects
|
|
// add effects to current effect list Effects
|
|
|
|
|
|
- let new_component = self.vdom.get_scope_mut(new_idx).unwrap();
|
|
|
|
|
|
+ let new_component = self.get_scope(&new_idx).unwrap();
|
|
|
|
|
|
log::debug!(
|
|
log::debug!(
|
|
"initializing component {:?} with height {:?}",
|
|
"initializing component {:?} with height {:?}",
|
|
@@ -375,58 +412,79 @@ impl<'bump> DiffMachine<'bump> {
|
|
);
|
|
);
|
|
|
|
|
|
// Run the scope for one iteration to initialize it
|
|
// Run the scope for one iteration to initialize it
|
|
- if new_component.run_scope(self.vdom) {
|
|
|
|
- // Take the node that was just generated from running the component
|
|
|
|
- let nextnode = new_component.frames.fin_head();
|
|
|
|
- self.stack.create_component(new_idx, nextnode);
|
|
|
|
|
|
+ //
|
|
|
|
+ todo!("run scope");
|
|
|
|
+ // if new_component.run_scope(self) {
|
|
|
|
+ // // Take the node that was just generated from running the component
|
|
|
|
+ // let nextnode = new_component.frames.fin_head();
|
|
|
|
+ // state.stack.create_component(new_idx, nextnode);
|
|
|
|
|
|
- //
|
|
|
|
- /*
|
|
|
|
- tree_item {
|
|
|
|
|
|
+ // //
|
|
|
|
+ // /*
|
|
|
|
+ // tree_item {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // }
|
|
|
|
|
|
- */
|
|
|
|
- if new_component.is_subtree_root.get() {
|
|
|
|
- self.stack.push_subtree();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // */
|
|
|
|
+ // if new_component.is_subtree_root.get() {
|
|
|
|
+ // state.stack.push_subtree();
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
|
|
// Finally, insert this scope as a seen node.
|
|
// Finally, insert this scope as a seen node.
|
|
- self.seen_scopes.insert(new_idx);
|
|
|
|
|
|
+ state.seen_scopes.insert(new_idx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn create_linked_node(&'bump self, state: &mut DiffState<'bump>, link: &'bump NodeLink) {
|
|
|
|
+ todo!()
|
|
}
|
|
}
|
|
|
|
|
|
// =================================
|
|
// =================================
|
|
// Tools for diffing nodes
|
|
// Tools for diffing nodes
|
|
// =================================
|
|
// =================================
|
|
|
|
|
|
- pub fn diff_node(&mut self, old_node: &'bump VNode<'bump>, new_node: &'bump VNode<'bump>) {
|
|
|
|
|
|
+ pub fn diff_node(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old_node: &'bump VNode<'bump>,
|
|
|
|
+ new_node: &'bump VNode<'bump>,
|
|
|
|
+ ) {
|
|
use VNode::*;
|
|
use VNode::*;
|
|
match (old_node, new_node) {
|
|
match (old_node, new_node) {
|
|
// Check the most common cases first
|
|
// Check the most common cases first
|
|
- (Text(old), Text(new)) => self.diff_text_nodes(old, new),
|
|
|
|
|
|
+ (Text(old), Text(new)) => self.diff_text_nodes(state, old, new),
|
|
(Component(old), Component(new)) => {
|
|
(Component(old), Component(new)) => {
|
|
- self.diff_component_nodes(old_node, new_node, old, new)
|
|
|
|
|
|
+ self.diff_component_nodes(state, old_node, new_node, old, new)
|
|
}
|
|
}
|
|
- (Fragment(old), Fragment(new)) => self.diff_fragment_nodes(old, new),
|
|
|
|
|
|
+ (Fragment(old), Fragment(new)) => self.diff_fragment_nodes(state, old, new),
|
|
(Anchor(old), Anchor(new)) => new.dom_id.set(old.dom_id.get()),
|
|
(Anchor(old), Anchor(new)) => new.dom_id.set(old.dom_id.get()),
|
|
- (Suspended(old), Suspended(new)) => self.diff_suspended_nodes(old, new),
|
|
|
|
- (Element(old), Element(new)) => self.diff_element_nodes(old, new, old_node, new_node),
|
|
|
|
|
|
+ (Suspended(old), Suspended(new)) => self.diff_suspended_nodes(state, old, new),
|
|
|
|
+ (Element(old), Element(new)) => {
|
|
|
|
+ self.diff_element_nodes(state, old, new, old_node, new_node)
|
|
|
|
+ }
|
|
|
|
+ (Linked(old), Linked(new)) => self.diff_linked_nodes(state, old, new),
|
|
|
|
|
|
// Anything else is just a basic replace and create
|
|
// Anything else is just a basic replace and create
|
|
(
|
|
(
|
|
- Component(_) | Fragment(_) | Text(_) | Element(_) | Anchor(_) | Suspended(_),
|
|
|
|
- Component(_) | Fragment(_) | Text(_) | Element(_) | Anchor(_) | Suspended(_),
|
|
|
|
- ) => self
|
|
|
|
|
|
+ Linked(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Anchor(_)
|
|
|
|
+ | Suspended(_),
|
|
|
|
+ Linked(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Anchor(_)
|
|
|
|
+ | Suspended(_),
|
|
|
|
+ ) => state
|
|
.stack
|
|
.stack
|
|
.create_node(new_node, MountType::Replace { old: old_node }),
|
|
.create_node(new_node, MountType::Replace { old: old_node }),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn diff_text_nodes(&mut self, old: &'bump VText<'bump>, new: &'bump VText<'bump>) {
|
|
|
|
|
|
+ fn diff_text_nodes(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump VText<'bump>,
|
|
|
|
+ new: &'bump VText<'bump>,
|
|
|
|
+ ) {
|
|
if let Some(root) = old.dom_id.get() {
|
|
if let Some(root) = old.dom_id.get() {
|
|
if old.text != new.text {
|
|
if old.text != new.text {
|
|
- self.mutations.set_text(new.text, root.as_u64());
|
|
|
|
|
|
+ state.mutations.set_text(new.text, root.as_u64());
|
|
}
|
|
}
|
|
|
|
|
|
new.dom_id.set(Some(root));
|
|
new.dom_id.set(Some(root));
|
|
@@ -434,7 +492,8 @@ impl<'bump> DiffMachine<'bump> {
|
|
}
|
|
}
|
|
|
|
|
|
fn diff_element_nodes(
|
|
fn diff_element_nodes(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
old: &'bump VElement<'bump>,
|
|
old: &'bump VElement<'bump>,
|
|
new: &'bump VElement<'bump>,
|
|
new: &'bump VElement<'bump>,
|
|
old_node: &'bump VNode<'bump>,
|
|
old_node: &'bump VNode<'bump>,
|
|
@@ -449,11 +508,11 @@ impl<'bump> DiffMachine<'bump> {
|
|
if new.tag_name != old.tag_name || new.namespace != old.namespace {
|
|
if new.tag_name != old.tag_name || new.namespace != old.namespace {
|
|
// maybe make this an instruction?
|
|
// maybe make this an instruction?
|
|
// issue is that we need the "vnode" but this method only has the velement
|
|
// issue is that we need the "vnode" but this method only has the velement
|
|
- self.stack.push_nodes_created(0);
|
|
|
|
- self.stack.push(DiffInstruction::Mount {
|
|
|
|
|
|
+ state.stack.push_nodes_created(0);
|
|
|
|
+ state.stack.push(DiffInstruction::Mount {
|
|
and: MountType::Replace { old: old_node },
|
|
and: MountType::Replace { old: old_node },
|
|
});
|
|
});
|
|
- self.create_element_node(new, new_node);
|
|
|
|
|
|
+ self.create_element_node(state, new, new_node);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -473,15 +532,15 @@ impl<'bump> DiffMachine<'bump> {
|
|
if old.attributes.len() == new.attributes.len() {
|
|
if old.attributes.len() == new.attributes.len() {
|
|
for (old_attr, new_attr) in old.attributes.iter().zip(new.attributes.iter()) {
|
|
for (old_attr, new_attr) in old.attributes.iter().zip(new.attributes.iter()) {
|
|
if old_attr.value != new_attr.value || new_attr.is_volatile {
|
|
if old_attr.value != new_attr.value || new_attr.is_volatile {
|
|
- self.mutations.set_attribute(new_attr, root.as_u64());
|
|
|
|
|
|
+ state.mutations.set_attribute(new_attr, root.as_u64());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
for attribute in old.attributes {
|
|
for attribute in old.attributes {
|
|
- self.mutations.remove_attribute(attribute, root.as_u64());
|
|
|
|
|
|
+ state.mutations.remove_attribute(attribute, root.as_u64());
|
|
}
|
|
}
|
|
for attribute in new.attributes {
|
|
for attribute in new.attributes {
|
|
- self.mutations.set_attribute(attribute, root.as_u64())
|
|
|
|
|
|
+ state.mutations.set_attribute(attribute, root.as_u64())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -493,44 +552,47 @@ impl<'bump> DiffMachine<'bump> {
|
|
// We also need to make sure that all listeners are properly attached to the parent scope (fix_listener)
|
|
// We also need to make sure that all listeners are properly attached to the parent scope (fix_listener)
|
|
//
|
|
//
|
|
// TODO: take a more efficient path than this
|
|
// TODO: take a more efficient path than this
|
|
- if let Some(cur_scope_id) = self.stack.current_scope() {
|
|
|
|
- let scope = self.vdom.get_scope(cur_scope_id).unwrap();
|
|
|
|
|
|
+ if let Some(cur_scope_id) = state.stack.current_scope() {
|
|
|
|
+ let scope = self.get_scope(&cur_scope_id).unwrap();
|
|
|
|
|
|
if old.listeners.len() == new.listeners.len() {
|
|
if old.listeners.len() == new.listeners.len() {
|
|
for (old_l, new_l) in old.listeners.iter().zip(new.listeners.iter()) {
|
|
for (old_l, new_l) in old.listeners.iter().zip(new.listeners.iter()) {
|
|
if old_l.event != new_l.event {
|
|
if old_l.event != new_l.event {
|
|
- self.mutations
|
|
|
|
|
|
+ state
|
|
|
|
+ .mutations
|
|
.remove_event_listener(old_l.event, root.as_u64());
|
|
.remove_event_listener(old_l.event, root.as_u64());
|
|
- self.mutations.new_event_listener(new_l, cur_scope_id);
|
|
|
|
|
|
+ state.mutations.new_event_listener(new_l, cur_scope_id);
|
|
}
|
|
}
|
|
new_l.mounted_node.set(old_l.mounted_node.get());
|
|
new_l.mounted_node.set(old_l.mounted_node.get());
|
|
self.attach_listener_to_scope(new_l, scope);
|
|
self.attach_listener_to_scope(new_l, scope);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
for listener in old.listeners {
|
|
for listener in old.listeners {
|
|
- self.mutations
|
|
|
|
|
|
+ state
|
|
|
|
+ .mutations
|
|
.remove_event_listener(listener.event, root.as_u64());
|
|
.remove_event_listener(listener.event, root.as_u64());
|
|
}
|
|
}
|
|
for listener in new.listeners {
|
|
for listener in new.listeners {
|
|
listener.mounted_node.set(Some(root));
|
|
listener.mounted_node.set(Some(root));
|
|
- self.mutations.new_event_listener(listener, cur_scope_id);
|
|
|
|
|
|
+ state.mutations.new_event_listener(listener, cur_scope_id);
|
|
self.attach_listener_to_scope(listener, scope);
|
|
self.attach_listener_to_scope(listener, scope);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if old.children.is_empty() && !new.children.is_empty() {
|
|
if old.children.is_empty() && !new.children.is_empty() {
|
|
- self.mutations.edits.push(PushRoot {
|
|
|
|
|
|
+ state.mutations.edits.push(PushRoot {
|
|
root: root.as_u64(),
|
|
root: root.as_u64(),
|
|
});
|
|
});
|
|
- self.stack.create_children(new.children, MountType::Append);
|
|
|
|
|
|
+ state.stack.create_children(new.children, MountType::Append);
|
|
} else {
|
|
} else {
|
|
- self.diff_children(old.children, new.children);
|
|
|
|
|
|
+ self.diff_children(state, old.children, new.children);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fn diff_component_nodes(
|
|
fn diff_component_nodes(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
old_node: &'bump VNode<'bump>,
|
|
old_node: &'bump VNode<'bump>,
|
|
new_node: &'bump VNode<'bump>,
|
|
new_node: &'bump VNode<'bump>,
|
|
|
|
|
|
@@ -543,50 +605,74 @@ impl<'bump> DiffMachine<'bump> {
|
|
if old.user_fc == new.user_fc {
|
|
if old.user_fc == new.user_fc {
|
|
log::debug!("Diffing component {:?} - {:?}", new.user_fc, scope_addr);
|
|
log::debug!("Diffing component {:?} - {:?}", new.user_fc, scope_addr);
|
|
//
|
|
//
|
|
- self.stack.scope_stack.push(scope_addr);
|
|
|
|
|
|
+ state.stack.scope_stack.push(scope_addr);
|
|
|
|
|
|
// Make sure the new component vnode is referencing the right scope id
|
|
// Make sure the new component vnode is referencing the right scope id
|
|
new.associated_scope.set(Some(scope_addr));
|
|
new.associated_scope.set(Some(scope_addr));
|
|
|
|
|
|
// make sure the component's caller function is up to date
|
|
// make sure the component's caller function is up to date
|
|
- let scope = self.vdom.get_scope_mut(scope_addr).unwrap();
|
|
|
|
- scope.update_scope_dependencies(new.caller);
|
|
|
|
|
|
+ let scope = self.get_scope(&scope_addr).unwrap();
|
|
|
|
+ let mut items = scope.items.borrow_mut();
|
|
|
|
|
|
// React doesn't automatically memoize, but we do.
|
|
// React doesn't automatically memoize, but we do.
|
|
- let props_are_the_same = old.comparator.unwrap();
|
|
|
|
|
|
+ let props_are_the_same = todo!("reworking component memoization");
|
|
|
|
+ // let props_are_the_same = todo!("reworking component memoization");
|
|
|
|
+ // let props_are_the_same = old.comparator.unwrap();
|
|
|
|
|
|
- if self.cfg.force_diff || !props_are_the_same(new) {
|
|
|
|
- let succeeded = scope.run_scope(self.vdom);
|
|
|
|
|
|
+ // if self.cfg.force_diff || !props_are_the_same(new) {
|
|
|
|
+ // let succeeded = scope.run_scope(self);
|
|
|
|
|
|
- if succeeded {
|
|
|
|
- self.diff_node(scope.frames.wip_head(), scope.frames.fin_head());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // if succeeded {
|
|
|
|
+ // self.diff_node(scope.frames.wip_head(), scope.frames.fin_head());
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
|
|
- self.stack.scope_stack.pop();
|
|
|
|
|
|
+ state.stack.scope_stack.pop();
|
|
} else {
|
|
} else {
|
|
- self.stack
|
|
|
|
|
|
+ state
|
|
|
|
+ .stack
|
|
.create_node(new_node, MountType::Replace { old: old_node });
|
|
.create_node(new_node, MountType::Replace { old: old_node });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn diff_fragment_nodes(&mut self, old: &'bump VFragment<'bump>, new: &'bump VFragment<'bump>) {
|
|
|
|
|
|
+ fn diff_fragment_nodes(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump VFragment<'bump>,
|
|
|
|
+ new: &'bump VFragment<'bump>,
|
|
|
|
+ ) {
|
|
// This is the case where options or direct vnodes might be used.
|
|
// This is the case where options or direct vnodes might be used.
|
|
// In this case, it's faster to just skip ahead to their diff
|
|
// In this case, it's faster to just skip ahead to their diff
|
|
if old.children.len() == 1 && new.children.len() == 1 {
|
|
if old.children.len() == 1 && new.children.len() == 1 {
|
|
- self.diff_node(&old.children[0], &new.children[0]);
|
|
|
|
|
|
+ self.diff_node(state, &old.children[0], &new.children[0]);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
debug_assert!(!old.children.is_empty());
|
|
debug_assert!(!old.children.is_empty());
|
|
debug_assert!(!new.children.is_empty());
|
|
debug_assert!(!new.children.is_empty());
|
|
|
|
|
|
- self.diff_children(old.children, new.children);
|
|
|
|
|
|
+ self.diff_children(state, old.children, new.children);
|
|
}
|
|
}
|
|
|
|
|
|
- fn diff_suspended_nodes(&mut self, old: &'bump VSuspended, new: &'bump VSuspended) {
|
|
|
|
|
|
+ fn diff_suspended_nodes(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump VSuspended,
|
|
|
|
+ new: &'bump VSuspended,
|
|
|
|
+ ) {
|
|
new.dom_id.set(old.dom_id.get());
|
|
new.dom_id.set(old.dom_id.get());
|
|
- self.attach_suspended_node_to_scope(new);
|
|
|
|
|
|
+ self.attach_suspended_node_to_scope(state, new);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn diff_linked_nodes(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump NodeLink,
|
|
|
|
+ new: &'bump NodeLink,
|
|
|
|
+ ) {
|
|
|
|
+ todo!();
|
|
|
|
+ // new.dom_id.set(old.dom_id.get());
|
|
|
|
+ // self.attach_linked_node_to_scope(state, new);
|
|
}
|
|
}
|
|
|
|
|
|
// =============================================
|
|
// =============================================
|
|
@@ -608,26 +694,32 @@ impl<'bump> DiffMachine<'bump> {
|
|
//
|
|
//
|
|
// Fragment nodes cannot generate empty children lists, so we can assume that when a list is empty, it belongs only
|
|
// Fragment nodes cannot generate empty children lists, so we can assume that when a list is empty, it belongs only
|
|
// to an element, and appending makes sense.
|
|
// to an element, and appending makes sense.
|
|
- fn diff_children(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
|
|
|
|
|
|
+ fn diff_children(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump [VNode<'bump>],
|
|
|
|
+ new: &'bump [VNode<'bump>],
|
|
|
|
+ ) {
|
|
// Remember, fragments can never be empty (they always have a single child)
|
|
// Remember, fragments can never be empty (they always have a single child)
|
|
match (old, new) {
|
|
match (old, new) {
|
|
([], []) => {}
|
|
([], []) => {}
|
|
([], _) => {
|
|
([], _) => {
|
|
// we need to push the
|
|
// we need to push the
|
|
- self.stack.create_children(new, MountType::Append);
|
|
|
|
|
|
+ state.stack.create_children(new, MountType::Append);
|
|
}
|
|
}
|
|
(_, []) => {
|
|
(_, []) => {
|
|
- self.remove_nodes(old, true);
|
|
|
|
|
|
+ self.remove_nodes(state, old, true);
|
|
}
|
|
}
|
|
([VNode::Anchor(old_anchor)], [VNode::Anchor(new_anchor)]) => {
|
|
([VNode::Anchor(old_anchor)], [VNode::Anchor(new_anchor)]) => {
|
|
old_anchor.dom_id.set(new_anchor.dom_id.get());
|
|
old_anchor.dom_id.set(new_anchor.dom_id.get());
|
|
}
|
|
}
|
|
([VNode::Anchor(_)], _) => {
|
|
([VNode::Anchor(_)], _) => {
|
|
- self.stack
|
|
|
|
|
|
+ state
|
|
|
|
+ .stack
|
|
.create_children(new, MountType::Replace { old: &old[0] });
|
|
.create_children(new, MountType::Replace { old: &old[0] });
|
|
}
|
|
}
|
|
(_, [VNode::Anchor(_)]) => {
|
|
(_, [VNode::Anchor(_)]) => {
|
|
- self.replace_and_create_many_with_one(old, &new[0]);
|
|
|
|
|
|
+ self.replace_and_create_many_with_one(state, old, &new[0]);
|
|
}
|
|
}
|
|
_ => {
|
|
_ => {
|
|
let new_is_keyed = new[0].key().is_some();
|
|
let new_is_keyed = new[0].key().is_some();
|
|
@@ -643,9 +735,9 @@ impl<'bump> DiffMachine<'bump> {
|
|
);
|
|
);
|
|
|
|
|
|
if new_is_keyed && old_is_keyed {
|
|
if new_is_keyed && old_is_keyed {
|
|
- self.diff_keyed_children(old, new);
|
|
|
|
|
|
+ self.diff_keyed_children(state, old, new);
|
|
} else {
|
|
} else {
|
|
- self.diff_non_keyed_children(old, new);
|
|
|
|
|
|
+ self.diff_non_keyed_children(state, old, new);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -659,20 +751,25 @@ impl<'bump> DiffMachine<'bump> {
|
|
// [... parent]
|
|
// [... parent]
|
|
//
|
|
//
|
|
// the change list stack is in the same state when this function returns.
|
|
// the change list stack is in the same state when this function returns.
|
|
- fn diff_non_keyed_children(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
|
|
|
|
|
|
+ fn diff_non_keyed_children(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump [VNode<'bump>],
|
|
|
|
+ new: &'bump [VNode<'bump>],
|
|
|
|
+ ) {
|
|
// Handled these cases in `diff_children` before calling this function.
|
|
// Handled these cases in `diff_children` before calling this function.
|
|
debug_assert!(!new.is_empty());
|
|
debug_assert!(!new.is_empty());
|
|
debug_assert!(!old.is_empty());
|
|
debug_assert!(!old.is_empty());
|
|
|
|
|
|
for (new, old) in new.iter().zip(old.iter()).rev() {
|
|
for (new, old) in new.iter().zip(old.iter()).rev() {
|
|
- self.stack.push(DiffInstruction::Diff { new, old });
|
|
|
|
|
|
+ state.stack.push(DiffInstruction::Diff { new, old });
|
|
}
|
|
}
|
|
|
|
|
|
use std::cmp::Ordering;
|
|
use std::cmp::Ordering;
|
|
match old.len().cmp(&new.len()) {
|
|
match old.len().cmp(&new.len()) {
|
|
- Ordering::Greater => self.remove_nodes(&old[new.len()..], true),
|
|
|
|
|
|
+ Ordering::Greater => self.remove_nodes(state, &old[new.len()..], true),
|
|
Ordering::Less => {
|
|
Ordering::Less => {
|
|
- self.stack.create_children(
|
|
|
|
|
|
+ state.stack.create_children(
|
|
&new[old.len()..],
|
|
&new[old.len()..],
|
|
MountType::InsertAfter {
|
|
MountType::InsertAfter {
|
|
other_node: old.last().unwrap(),
|
|
other_node: old.last().unwrap(),
|
|
@@ -701,7 +798,12 @@ impl<'bump> DiffMachine<'bump> {
|
|
// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
|
|
// https://github.com/infernojs/inferno/blob/36fd96/packages/inferno/src/DOM/patching.ts#L530-L739
|
|
//
|
|
//
|
|
// The stack is empty upon entry.
|
|
// The stack is empty upon entry.
|
|
- fn diff_keyed_children(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
|
|
|
|
|
|
+ fn diff_keyed_children(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump [VNode<'bump>],
|
|
|
|
+ new: &'bump [VNode<'bump>],
|
|
|
|
+ ) {
|
|
if cfg!(debug_assertions) {
|
|
if cfg!(debug_assertions) {
|
|
let mut keys = fxhash::FxHashSet::default();
|
|
let mut keys = fxhash::FxHashSet::default();
|
|
let mut assert_unique_keys = |children: &'bump [VNode<'bump>]| {
|
|
let mut assert_unique_keys = |children: &'bump [VNode<'bump>]| {
|
|
@@ -729,7 +831,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
//
|
|
//
|
|
// `shared_prefix_count` is the count of how many nodes at the start of
|
|
// `shared_prefix_count` is the count of how many nodes at the start of
|
|
// `new` and `old` share the same keys.
|
|
// `new` and `old` share the same keys.
|
|
- let (left_offset, right_offset) = match self.diff_keyed_ends(old, new) {
|
|
|
|
|
|
+ let (left_offset, right_offset) = match self.diff_keyed_ends(state, old, new) {
|
|
Some(count) => count,
|
|
Some(count) => count,
|
|
None => return,
|
|
None => return,
|
|
};
|
|
};
|
|
@@ -739,7 +841,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
// right_offset,
|
|
// right_offset,
|
|
// );
|
|
// );
|
|
|
|
|
|
- // log::debug!("stack before lo is {:#?}", self.stack.instructions);
|
|
|
|
|
|
+ // log::debug!("stack before lo is {:#?}", state.stack.instructions);
|
|
// Ok, we now hopefully have a smaller range of children in the middle
|
|
// Ok, we now hopefully have a smaller range of children in the middle
|
|
// within which to re-order nodes with the same keys, remove old nodes with
|
|
// within which to re-order nodes with the same keys, remove old nodes with
|
|
// now-unused keys, and create new nodes with fresh keys.
|
|
// now-unused keys, and create new nodes with fresh keys.
|
|
@@ -753,14 +855,14 @@ impl<'bump> DiffMachine<'bump> {
|
|
);
|
|
);
|
|
if new_middle.is_empty() {
|
|
if new_middle.is_empty() {
|
|
// remove the old elements
|
|
// remove the old elements
|
|
- self.remove_nodes(old_middle, true);
|
|
|
|
|
|
+ self.remove_nodes(state, old_middle, true);
|
|
} else if old_middle.is_empty() {
|
|
} else if old_middle.is_empty() {
|
|
// there were no old elements, so just create the new elements
|
|
// there were no old elements, so just create the new elements
|
|
// we need to find the right "foothold" though - we shouldn't use the "append" at all
|
|
// we need to find the right "foothold" though - we shouldn't use the "append" at all
|
|
if left_offset == 0 {
|
|
if left_offset == 0 {
|
|
// insert at the beginning of the old list
|
|
// insert at the beginning of the old list
|
|
let foothold = &old[old.len() - right_offset];
|
|
let foothold = &old[old.len() - right_offset];
|
|
- self.stack.create_children(
|
|
|
|
|
|
+ state.stack.create_children(
|
|
new_middle,
|
|
new_middle,
|
|
MountType::InsertBefore {
|
|
MountType::InsertBefore {
|
|
other_node: foothold,
|
|
other_node: foothold,
|
|
@@ -769,7 +871,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
} else if right_offset == 0 {
|
|
} else if right_offset == 0 {
|
|
// insert at the end the old list
|
|
// insert at the end the old list
|
|
let foothold = old.last().unwrap();
|
|
let foothold = old.last().unwrap();
|
|
- self.stack.create_children(
|
|
|
|
|
|
+ state.stack.create_children(
|
|
new_middle,
|
|
new_middle,
|
|
MountType::InsertAfter {
|
|
MountType::InsertAfter {
|
|
other_node: foothold,
|
|
other_node: foothold,
|
|
@@ -778,7 +880,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
} else {
|
|
} else {
|
|
// inserting in the middle
|
|
// inserting in the middle
|
|
let foothold = &old[left_offset - 1];
|
|
let foothold = &old[left_offset - 1];
|
|
- self.stack.create_children(
|
|
|
|
|
|
+ state.stack.create_children(
|
|
new_middle,
|
|
new_middle,
|
|
MountType::InsertAfter {
|
|
MountType::InsertAfter {
|
|
other_node: foothold,
|
|
other_node: foothold,
|
|
@@ -786,10 +888,10 @@ impl<'bump> DiffMachine<'bump> {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- self.diff_keyed_middle(old_middle, new_middle);
|
|
|
|
|
|
+ self.diff_keyed_middle(state, old_middle, new_middle);
|
|
}
|
|
}
|
|
|
|
|
|
- log::debug!("stack after km is {:#?}", self.stack.instructions);
|
|
|
|
|
|
+ log::debug!("stack after km is {:#?}", state.stack.instructions);
|
|
}
|
|
}
|
|
|
|
|
|
/// Diff both ends of the children that share keys.
|
|
/// Diff both ends of the children that share keys.
|
|
@@ -798,7 +900,8 @@ impl<'bump> DiffMachine<'bump> {
|
|
///
|
|
///
|
|
/// If there is no offset, then this function returns None and the diffing is complete.
|
|
/// If there is no offset, then this function returns None and the diffing is complete.
|
|
fn diff_keyed_ends(
|
|
fn diff_keyed_ends(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
old: &'bump [VNode<'bump>],
|
|
old: &'bump [VNode<'bump>],
|
|
new: &'bump [VNode<'bump>],
|
|
new: &'bump [VNode<'bump>],
|
|
) -> Option<(usize, usize)> {
|
|
) -> Option<(usize, usize)> {
|
|
@@ -809,14 +912,14 @@ impl<'bump> DiffMachine<'bump> {
|
|
if old.key() != new.key() {
|
|
if old.key() != new.key() {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- self.stack.push(DiffInstruction::Diff { old, new });
|
|
|
|
|
|
+ state.stack.push(DiffInstruction::Diff { old, new });
|
|
left_offset += 1;
|
|
left_offset += 1;
|
|
}
|
|
}
|
|
|
|
|
|
// If that was all of the old children, then create and append the remaining
|
|
// If that was all of the old children, then create and append the remaining
|
|
// new children and we're finished.
|
|
// new children and we're finished.
|
|
if left_offset == old.len() {
|
|
if left_offset == old.len() {
|
|
- self.stack.create_children(
|
|
|
|
|
|
+ state.stack.create_children(
|
|
&new[left_offset..],
|
|
&new[left_offset..],
|
|
MountType::InsertAfter {
|
|
MountType::InsertAfter {
|
|
other_node: old.last().unwrap(),
|
|
other_node: old.last().unwrap(),
|
|
@@ -828,7 +931,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
// And if that was all of the new children, then remove all of the remaining
|
|
// And if that was all of the new children, then remove all of the remaining
|
|
// old children and we're finished.
|
|
// old children and we're finished.
|
|
if left_offset == new.len() {
|
|
if left_offset == new.len() {
|
|
- self.remove_nodes(&old[left_offset..], true);
|
|
|
|
|
|
+ self.remove_nodes(state, &old[left_offset..], true);
|
|
return None;
|
|
return None;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -839,7 +942,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
if old.key() != new.key() {
|
|
if old.key() != new.key() {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- self.diff_node(old, new);
|
|
|
|
|
|
+ self.diff_node(state, old, new);
|
|
right_offset += 1;
|
|
right_offset += 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -859,7 +962,12 @@ impl<'bump> DiffMachine<'bump> {
|
|
// This function will load the appropriate nodes onto the stack and do diffing in place.
|
|
// This function will load the appropriate nodes onto the stack and do diffing in place.
|
|
//
|
|
//
|
|
// Upon exit from this function, it will be restored to that same state.
|
|
// Upon exit from this function, it will be restored to that same state.
|
|
- fn diff_keyed_middle(&mut self, old: &'bump [VNode<'bump>], new: &'bump [VNode<'bump>]) {
|
|
|
|
|
|
+ fn diff_keyed_middle(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ old: &'bump [VNode<'bump>],
|
|
|
|
+ new: &'bump [VNode<'bump>],
|
|
|
|
+ ) {
|
|
/*
|
|
/*
|
|
1. Map the old keys into a numerical ordering based on indices.
|
|
1. Map the old keys into a numerical ordering based on indices.
|
|
2. Create a map of old key to its index
|
|
2. Create a map of old key to its index
|
|
@@ -923,7 +1031,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
log::debug!("old_key_to_old_index, {:#?}", old_key_to_old_index);
|
|
log::debug!("old_key_to_old_index, {:#?}", old_key_to_old_index);
|
|
log::debug!("new_index_to_old_index, {:#?}", new_index_to_old_index);
|
|
log::debug!("new_index_to_old_index, {:#?}", new_index_to_old_index);
|
|
log::debug!("shared_keys, {:#?}", shared_keys);
|
|
log::debug!("shared_keys, {:#?}", shared_keys);
|
|
- self.replace_and_create_many_with_many(old, new);
|
|
|
|
|
|
+ self.replace_and_create_many_with_many(state, old, new);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -967,15 +1075,15 @@ impl<'bump> DiffMachine<'bump> {
|
|
// add mount instruction for the last items not covered by the lis
|
|
// add mount instruction for the last items not covered by the lis
|
|
let first_lis = *lis_sequence.first().unwrap();
|
|
let first_lis = *lis_sequence.first().unwrap();
|
|
if first_lis > 0 {
|
|
if first_lis > 0 {
|
|
- self.stack.push_nodes_created(0);
|
|
|
|
- self.stack.push(DiffInstruction::Mount {
|
|
|
|
|
|
+ state.stack.push_nodes_created(0);
|
|
|
|
+ state.stack.push(DiffInstruction::Mount {
|
|
and: MountType::InsertBefore {
|
|
and: MountType::InsertBefore {
|
|
other_node: &new[first_lis],
|
|
other_node: &new[first_lis],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|
|
for (idx, new_node) in new[..first_lis].iter().enumerate().rev() {
|
|
for (idx, new_node) in new[..first_lis].iter().enumerate().rev() {
|
|
- apply(idx, new_node, &mut self.stack);
|
|
|
|
|
|
+ apply(idx, new_node, &mut state.stack);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -984,14 +1092,14 @@ impl<'bump> DiffMachine<'bump> {
|
|
let mut last = *lis_iter.next().unwrap();
|
|
let mut last = *lis_iter.next().unwrap();
|
|
for next in lis_iter {
|
|
for next in lis_iter {
|
|
if last - next > 1 {
|
|
if last - next > 1 {
|
|
- self.stack.push_nodes_created(0);
|
|
|
|
- self.stack.push(DiffInstruction::Mount {
|
|
|
|
|
|
+ state.stack.push_nodes_created(0);
|
|
|
|
+ state.stack.push(DiffInstruction::Mount {
|
|
and: MountType::InsertBefore {
|
|
and: MountType::InsertBefore {
|
|
other_node: &new[last],
|
|
other_node: &new[last],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
for (idx, new_node) in new[(next + 1)..last].iter().enumerate().rev() {
|
|
for (idx, new_node) in new[(next + 1)..last].iter().enumerate().rev() {
|
|
- apply(idx + next + 1, new_node, &mut self.stack);
|
|
|
|
|
|
+ apply(idx + next + 1, new_node, &mut state.stack);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
last = *next;
|
|
last = *next;
|
|
@@ -1000,19 +1108,19 @@ impl<'bump> DiffMachine<'bump> {
|
|
// add mount instruction for the first items not covered by the lis
|
|
// add mount instruction for the first items not covered by the lis
|
|
let last = *lis_sequence.last().unwrap();
|
|
let last = *lis_sequence.last().unwrap();
|
|
if last < (new.len() - 1) {
|
|
if last < (new.len() - 1) {
|
|
- self.stack.push_nodes_created(0);
|
|
|
|
- self.stack.push(DiffInstruction::Mount {
|
|
|
|
|
|
+ state.stack.push_nodes_created(0);
|
|
|
|
+ state.stack.push(DiffInstruction::Mount {
|
|
and: MountType::InsertAfter {
|
|
and: MountType::InsertAfter {
|
|
other_node: &new[last],
|
|
other_node: &new[last],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
for (idx, new_node) in new[(last + 1)..].iter().enumerate().rev() {
|
|
for (idx, new_node) in new[(last + 1)..].iter().enumerate().rev() {
|
|
- apply(idx + last + 1, new_node, &mut self.stack);
|
|
|
|
|
|
+ apply(idx + last + 1, new_node, &mut state.stack);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
for idx in lis_sequence.iter().rev() {
|
|
for idx in lis_sequence.iter().rev() {
|
|
- self.stack.push(DiffInstruction::Diff {
|
|
|
|
|
|
+ state.stack.push(DiffInstruction::Diff {
|
|
new: &new[*idx],
|
|
new: &new[*idx],
|
|
old: &old[new_index_to_old_index[*idx]],
|
|
old: &old[new_index_to_old_index[*idx]],
|
|
});
|
|
});
|
|
@@ -1023,7 +1131,7 @@ impl<'bump> DiffMachine<'bump> {
|
|
// Utilities
|
|
// Utilities
|
|
// =====================
|
|
// =====================
|
|
|
|
|
|
- fn find_last_element(&mut self, vnode: &'bump VNode<'bump>) -> Option<ElementId> {
|
|
|
|
|
|
+ fn find_last_element(&'bump self, vnode: &'bump VNode<'bump>) -> Option<ElementId> {
|
|
let mut search_node = Some(vnode);
|
|
let mut search_node = Some(vnode);
|
|
|
|
|
|
loop {
|
|
loop {
|
|
@@ -1032,20 +1140,22 @@ impl<'bump> DiffMachine<'bump> {
|
|
VNode::Element(t) => break t.dom_id.get(),
|
|
VNode::Element(t) => break t.dom_id.get(),
|
|
VNode::Suspended(t) => break t.dom_id.get(),
|
|
VNode::Suspended(t) => break t.dom_id.get(),
|
|
VNode::Anchor(t) => break t.dom_id.get(),
|
|
VNode::Anchor(t) => break t.dom_id.get(),
|
|
-
|
|
|
|
|
|
+ VNode::Linked(_) => {
|
|
|
|
+ todo!()
|
|
|
|
+ }
|
|
VNode::Fragment(frag) => {
|
|
VNode::Fragment(frag) => {
|
|
search_node = frag.children.last();
|
|
search_node = frag.children.last();
|
|
}
|
|
}
|
|
VNode::Component(el) => {
|
|
VNode::Component(el) => {
|
|
let scope_id = el.associated_scope.get().unwrap();
|
|
let scope_id = el.associated_scope.get().unwrap();
|
|
- let scope = self.vdom.get_scope(scope_id).unwrap();
|
|
|
|
- search_node = Some(scope.root_node());
|
|
|
|
|
|
+ // let scope = self.get_scope(&scope_id).unwrap();
|
|
|
|
+ search_node = Some(self.root_node(&scope_id));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn find_first_element_id(&mut self, vnode: &'bump VNode<'bump>) -> Option<ElementId> {
|
|
|
|
|
|
+ fn find_first_element_id(&'bump self, vnode: &'bump VNode<'bump>) -> Option<ElementId> {
|
|
let mut search_node = Some(vnode);
|
|
let mut search_node = Some(vnode);
|
|
|
|
|
|
loop {
|
|
loop {
|
|
@@ -1056,8 +1166,11 @@ impl<'bump> DiffMachine<'bump> {
|
|
}
|
|
}
|
|
VNode::Component(el) => {
|
|
VNode::Component(el) => {
|
|
let scope_id = el.associated_scope.get().unwrap();
|
|
let scope_id = el.associated_scope.get().unwrap();
|
|
- let scope = self.vdom.get_scope(scope_id).unwrap();
|
|
|
|
- search_node = Some(scope.root_node());
|
|
|
|
|
|
+ // let scope = self.get_scope(&scope_id).unwrap();
|
|
|
|
+ search_node = Some(self.root_node(&scope_id));
|
|
|
|
+ }
|
|
|
|
+ VNode::Linked(link) => {
|
|
|
|
+ todo!("linked")
|
|
}
|
|
}
|
|
VNode::Text(t) => break t.dom_id.get(),
|
|
VNode::Text(t) => break t.dom_id.get(),
|
|
VNode::Element(t) => break t.dom_id.get(),
|
|
VNode::Element(t) => break t.dom_id.get(),
|
|
@@ -1068,23 +1181,26 @@ impl<'bump> DiffMachine<'bump> {
|
|
}
|
|
}
|
|
|
|
|
|
fn replace_and_create_many_with_one(
|
|
fn replace_and_create_many_with_one(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
old: &'bump [VNode<'bump>],
|
|
old: &'bump [VNode<'bump>],
|
|
new: &'bump VNode<'bump>,
|
|
new: &'bump VNode<'bump>,
|
|
) {
|
|
) {
|
|
if let Some(first_old) = old.get(0) {
|
|
if let Some(first_old) = old.get(0) {
|
|
- self.remove_nodes(&old[1..], true);
|
|
|
|
- self.stack
|
|
|
|
|
|
+ self.remove_nodes(state, &old[1..], true);
|
|
|
|
+ state
|
|
|
|
+ .stack
|
|
.create_node(new, MountType::Replace { old: first_old });
|
|
.create_node(new, MountType::Replace { old: first_old });
|
|
} else {
|
|
} else {
|
|
- self.stack.create_node(new, MountType::Append {});
|
|
|
|
|
|
+ state.stack.create_node(new, MountType::Append {});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// schedules nodes for garbage collection and pushes "remove" to the mutation stack
|
|
/// schedules nodes for garbage collection and pushes "remove" to the mutation stack
|
|
/// remove can happen whenever
|
|
/// remove can happen whenever
|
|
fn remove_nodes(
|
|
fn remove_nodes(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
nodes: impl IntoIterator<Item = &'bump VNode<'bump>>,
|
|
nodes: impl IntoIterator<Item = &'bump VNode<'bump>>,
|
|
gen_muts: bool,
|
|
gen_muts: bool,
|
|
) {
|
|
) {
|
|
@@ -1093,50 +1209,54 @@ impl<'bump> DiffMachine<'bump> {
|
|
match node {
|
|
match node {
|
|
VNode::Text(t) => {
|
|
VNode::Text(t) => {
|
|
let id = t.dom_id.get().unwrap();
|
|
let id = t.dom_id.get().unwrap();
|
|
- self.vdom.collect_garbage(id);
|
|
|
|
|
|
+ self.collect_garbage(id);
|
|
|
|
|
|
if gen_muts {
|
|
if gen_muts {
|
|
- self.mutations.remove(id.as_u64());
|
|
|
|
|
|
+ state.mutations.remove(id.as_u64());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
VNode::Suspended(s) => {
|
|
VNode::Suspended(s) => {
|
|
let id = s.dom_id.get().unwrap();
|
|
let id = s.dom_id.get().unwrap();
|
|
- self.vdom.collect_garbage(id);
|
|
|
|
|
|
+ self.collect_garbage(id);
|
|
|
|
|
|
if gen_muts {
|
|
if gen_muts {
|
|
- self.mutations.remove(id.as_u64());
|
|
|
|
|
|
+ state.mutations.remove(id.as_u64());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
VNode::Anchor(a) => {
|
|
VNode::Anchor(a) => {
|
|
let id = a.dom_id.get().unwrap();
|
|
let id = a.dom_id.get().unwrap();
|
|
- self.vdom.collect_garbage(id);
|
|
|
|
|
|
+ self.collect_garbage(id);
|
|
|
|
|
|
if gen_muts {
|
|
if gen_muts {
|
|
- self.mutations.remove(id.as_u64());
|
|
|
|
|
|
+ state.mutations.remove(id.as_u64());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
VNode::Element(e) => {
|
|
VNode::Element(e) => {
|
|
let id = e.dom_id.get().unwrap();
|
|
let id = e.dom_id.get().unwrap();
|
|
|
|
|
|
if gen_muts {
|
|
if gen_muts {
|
|
- self.mutations.remove(id.as_u64());
|
|
|
|
|
|
+ state.mutations.remove(id.as_u64());
|
|
}
|
|
}
|
|
|
|
|
|
- self.remove_nodes(e.children, false);
|
|
|
|
|
|
+ self.remove_nodes(state, e.children, false);
|
|
}
|
|
}
|
|
|
|
|
|
VNode::Fragment(f) => {
|
|
VNode::Fragment(f) => {
|
|
- self.remove_nodes(f.children, gen_muts);
|
|
|
|
|
|
+ self.remove_nodes(state, f.children, gen_muts);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ VNode::Linked(l) => {
|
|
|
|
+ todo!()
|
|
}
|
|
}
|
|
|
|
|
|
VNode::Component(c) => {
|
|
VNode::Component(c) => {
|
|
let scope_id = c.associated_scope.get().unwrap();
|
|
let scope_id = c.associated_scope.get().unwrap();
|
|
- let scope = self.vdom.get_scope_mut(scope_id).unwrap();
|
|
|
|
- let root = scope.root_node();
|
|
|
|
- self.remove_nodes(Some(root), gen_muts);
|
|
|
|
|
|
+ // let scope = self.get_scope(&scope_id).unwrap();
|
|
|
|
+ let root = self.root_node(&scope_id);
|
|
|
|
+ self.remove_nodes(state, Some(root), gen_muts);
|
|
|
|
|
|
log::debug!("Destroying scope {:?}", scope_id);
|
|
log::debug!("Destroying scope {:?}", scope_id);
|
|
- let mut s = self.vdom.try_remove(scope_id).unwrap();
|
|
|
|
|
|
+ let mut s = self.try_remove(&scope_id).unwrap();
|
|
s.hooks.clear_hooks();
|
|
s.hooks.clear_hooks();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1147,38 +1267,44 @@ impl<'bump> DiffMachine<'bump> {
|
|
///
|
|
///
|
|
/// The new nodes *will* be created - don't create them yourself!
|
|
/// The new nodes *will* be created - don't create them yourself!
|
|
fn replace_and_create_many_with_many(
|
|
fn replace_and_create_many_with_many(
|
|
- &mut self,
|
|
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
old: &'bump [VNode<'bump>],
|
|
old: &'bump [VNode<'bump>],
|
|
new: &'bump [VNode<'bump>],
|
|
new: &'bump [VNode<'bump>],
|
|
) {
|
|
) {
|
|
if let Some(first_old) = old.get(0) {
|
|
if let Some(first_old) = old.get(0) {
|
|
- self.remove_nodes(&old[1..], true);
|
|
|
|
- self.stack
|
|
|
|
|
|
+ self.remove_nodes(state, &old[1..], true);
|
|
|
|
+ state
|
|
|
|
+ .stack
|
|
.create_children(new, MountType::Replace { old: first_old })
|
|
.create_children(new, MountType::Replace { old: first_old })
|
|
} else {
|
|
} else {
|
|
- self.stack.create_children(new, MountType::Append {});
|
|
|
|
|
|
+ state.stack.create_children(new, MountType::Append {});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// Adds a listener closure to a scope during diff.
|
|
/// Adds a listener closure to a scope during diff.
|
|
- fn attach_listener_to_scope<'a>(&mut self, listener: &'a Listener<'a>, scope: &ScopeInner) {
|
|
|
|
- let mut queue = scope.listeners.borrow_mut();
|
|
|
|
- let long_listener: &'a Listener<'static> = unsafe { std::mem::transmute(listener) };
|
|
|
|
- queue.push(long_listener as *const _)
|
|
|
|
|
|
+ fn attach_listener_to_scope(&'bump self, listener: &'bump Listener<'bump>, scope: &Scope) {
|
|
|
|
+ let long_listener = unsafe { std::mem::transmute(listener) };
|
|
|
|
+ scope.items.borrow_mut().listeners.push(long_listener)
|
|
}
|
|
}
|
|
|
|
|
|
- fn attach_suspended_node_to_scope(&mut self, suspended: &'bump VSuspended) {
|
|
|
|
- if let Some(scope) = self
|
|
|
|
|
|
+ fn attach_suspended_node_to_scope(
|
|
|
|
+ &'bump self,
|
|
|
|
+ state: &mut DiffState<'bump>,
|
|
|
|
+ suspended: &'bump VSuspended,
|
|
|
|
+ ) {
|
|
|
|
+ if let Some(scope) = state
|
|
.stack
|
|
.stack
|
|
.current_scope()
|
|
.current_scope()
|
|
- .and_then(|id| self.vdom.get_scope_mut(id))
|
|
|
|
|
|
+ .and_then(|id| self.get_scope(&id))
|
|
{
|
|
{
|
|
// safety: this lifetime is managed by the logic on scope
|
|
// safety: this lifetime is managed by the logic on scope
|
|
- let extended: &VSuspended<'static> = unsafe { std::mem::transmute(suspended) };
|
|
|
|
|
|
+ let extended = unsafe { std::mem::transmute(suspended) };
|
|
scope
|
|
scope
|
|
- .suspended_nodes
|
|
|
|
|
|
+ .items
|
|
.borrow_mut()
|
|
.borrow_mut()
|
|
- .insert(suspended.task_id, extended as *const _);
|
|
|
|
|
|
+ .suspended_nodes
|
|
|
|
+ .insert(suspended.task_id, extended);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|