wip: diffing approach slightly broken
This commit is contained in:
1 parent
9d0727edab
commit
4e48e0514e
6 files changed
+32
-47
No files matched your search
@@ -149,10 +149,14 @@ impl<'a> DiffMachine<'a> {
|
||||
|
||||
(VNode::Component(cold), VNode::Component(cnew)) => {
|
||||
// todo!("should not happen")
|
||||
// self.change_list.commit_traversal();
|
||||
if cold.user_fc == cnew.user_fc {
|
||||
// todo: create a stable addr
|
||||
let caller = Rc::downgrade(&cnew.caller);
|
||||
let id = cold.stable_addr.borrow().unwrap();
|
||||
*cnew.stable_addr.borrow_mut() = Some(id);
|
||||
*cnew.ass_scope.borrow_mut() = *cold.ass_scope.borrow();
|
||||
|
||||
let scope = Rc::downgrade(&cold.ass_scope);
|
||||
self.lifecycle_events
|
||||
.push_back(LifeCycleEvent::PropsChanged { caller, id, scope });
|
||||
@@ -169,19 +173,6 @@ impl<'a> DiffMachine<'a> {
|
||||
new_scope,
|
||||
});
|
||||
}
|
||||
|
||||
// let comparator = &cnew.comparator.0;
|
||||
// let old_props = cold.raw_props.as_ref();
|
||||
// let has_changed = comparator(old_props);
|
||||
|
||||
// if has_changed {
|
||||
// self.lifecycle_events
|
||||
// .push_back(LifeCycleEvent::PropsChanged);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// the component is the same and hasn't changed
|
||||
// migrate props over (so the addr remains stable) but don't rerun the component
|
||||
}
|
||||
|
||||
// todo: knock out any listeners
|
||||
@@ -448,13 +439,9 @@ impl<'a> DiffMachine<'a> {
|
||||
|
||||
if new_is_keyed && old_is_keyed {
|
||||
let t = self.change_list.next_temporary();
|
||||
// diff_keyed_children(self.change_list, old, new);
|
||||
// diff_keyed_children(self.change_list, old, new, cached_roots);
|
||||
// diff_keyed_children(cached_set, self.change_list, registry, old, new, cached_roots);
|
||||
self.change_list.set_next_temporary(t);
|
||||
} else {
|
||||
self.diff_non_keyed_children(old, new);
|
||||
// diff_non_keyed_children(cached_set, change_list, registry, old, new, cached_roots);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,8 +467,6 @@ impl<'a> DiffMachine<'a> {
|
||||
//
|
||||
// Upon exiting, the change list stack is in the same state.
|
||||
fn diff_keyed_children(&mut self, old: &[VNode<'a>], new: &[VNode<'a>]) {
|
||||
// let DiffState { change_list, queue } = &*state;
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
let mut keys = fxhash::FxHashSet::default();
|
||||
let mut assert_unique_keys = |children: &[VNode]| {
|
||||
|
||||
@@ -325,29 +325,17 @@ impl<'a> EditMachine<'a> {
|
||||
|
||||
pub fn create_text_node(&mut self, text: &'a str) {
|
||||
debug_assert!(self.traversal_is_committed());
|
||||
// debug!("emit: create_text_node({:?})", text);
|
||||
// self.emitter.create_text_node(text);
|
||||
self.emitter.push(Edit::CreateTextNode { text });
|
||||
}
|
||||
|
||||
pub fn create_element(&mut self, tag_name: &'a str) {
|
||||
// debug_assert!(self.traversal_is_committed());
|
||||
// debug!("emit: create_element({:?})", tag_name);
|
||||
// let tag_name_id = self.ensure_string(tag_name);
|
||||
debug_assert!(self.traversal_is_committed());;
|
||||
self.emitter.push(Edit::CreateElement { tag_name });
|
||||
// self.emitter.create_element(tag_name);
|
||||
// self.emitter.create_element(tag_name_id.into());
|
||||
}
|
||||
|
||||
pub fn create_element_ns(&mut self, tag_name: &'a str, ns: &'a str) {
|
||||
debug_assert!(self.traversal_is_committed());
|
||||
// debug!("emit: create_element_ns({:?}, {:?})", tag_name, ns);
|
||||
// let tag_name_id = self.ensure_string(tag_name);
|
||||
// let ns_id = self.ensure_string(ns);
|
||||
// self.emitter.create_element_ns(tag_name, ns);
|
||||
self.emitter.push(Edit::CreateElementNs { tag_name, ns });
|
||||
// self.emitter
|
||||
// .create_element_ns(tag_name_id.into(), ns_id.into());
|
||||
}
|
||||
|
||||
pub fn push_force_new_listeners(&mut self) -> bool {
|
||||
@@ -364,7 +352,6 @@ impl<'a> EditMachine<'a> {
|
||||
pub fn new_event_listener(&mut self, event: &'a str, scope: ScopeIdx, id: usize) {
|
||||
debug_assert!(self.traversal_is_committed());
|
||||
self.emitter.push(Edit::NewListener { event, scope, id });
|
||||
// log::debug!("emit: new_event_listener({:?})", listener);
|
||||
}
|
||||
|
||||
pub fn update_event_listener(&mut self, event: &'a str, scope: ScopeIdx, id: usize) {
|
||||
|
||||
@@ -117,8 +117,9 @@ impl VirtualDom {
|
||||
c.run_scope()?;
|
||||
|
||||
diff_machine.change_list.load_known_root(id);
|
||||
|
||||
|
||||
diff_machine.diff_node(c.old_frame(), c.new_frame());
|
||||
diff_machine.change_list.save_known_root(id);
|
||||
}
|
||||
}
|
||||
LifeCycleEvent::PropsChanged { caller, id, scope } => {
|
||||
@@ -131,7 +132,7 @@ impl VirtualDom {
|
||||
let p = &mut *(very_unsafe_components);
|
||||
// todo, hook up the parent/child indexes properly
|
||||
// let idx = p.insert_with(|f| Scope::new(caller, f, None));
|
||||
let c = p.get_mut(idx).unwrap();
|
||||
let c = p.get_mut(idx).unwrap();
|
||||
c.run_scope()?;
|
||||
|
||||
diff_machine.change_list.load_known_root(id);
|
||||
@@ -193,7 +194,7 @@ impl VirtualDom {
|
||||
component.call_listener(event);
|
||||
component.run_scope()?;
|
||||
|
||||
let mut diff_machine = DiffMachine::new();
|
||||
// let mut diff_machine = DiffMachine::new();
|
||||
// let mut diff_machine = DiffMachine::new(&self.diff_bump);
|
||||
|
||||
// diff_machine.diff_node(component.old_frame(), component.new_frame());
|
||||
|
||||
Reference in new issue
Block a user