wip: livehost bones

This commit is contained in:
Jonathan Kelley committed 2021-03-16 11:03:59 -04:00
1 parent 5b7887d76c
commit 7856f2b153
17 files changed
+154 -117

No files matched your search

+16 -10
View File
@@ -259,11 +259,11 @@ impl<'a> DiffMachine<'a> {
let id = get_id();
*component.stable_addr.as_ref().borrow_mut() = Some(id);
self.change_list.save_known_root(id);
let scope = Rc::downgrade(&component.ass_scope);
let scope = Rc::downgrade(&component.ass_scope);
self.lifecycle_events.push_back(LifeCycleEvent::Mount {
caller: Rc::downgrade(&component.caller),
id,
scope
scope,
});
}
VNode::Suspended => {
@@ -286,20 +286,26 @@ impl<'a> DiffMachine<'a> {
}
'outer1: for (_l_idx, new_l) in new.iter().enumerate() {
// unsafe {
// Safety relies on removing `new_l` from the registry manually at
// the end of its lifetime. This happens below in the `'outer2`
// loop, and elsewhere in diffing when removing old dom trees.
// registry.add(new_l);
// }
// go through each new listener
// find its corresponding partner in the old list
// if any characteristics changed, remove and then re-add
// if nothing changed, then just move on
let event_type = new_l.event;
for old_l in old {
if new_l.event == old_l.event {
if new_l.id != old_l.id {
self.change_list.remove_event_listener(event_type);
self.change_list
.update_event_listener(event_type, new_l.scope, new_l.id)
}
// if let Some(scope) = self.current_idx {
// let cb = CbIdx::from_gi_index(scope, l_idx);
self.change_list
.update_event_listener(event_type, new_l.scope, new_l.id);
// self.change_list
// .update_event_listener(event_type, new_l.scope, new_l.id);
// }
continue 'outer1;
+3 -4
View File
@@ -83,7 +83,8 @@ impl Scope {
/// This function downcasts the function pointer based on the stored props_type
///
/// Props is ?Sized because we borrow the props and don't need to know the size. P (sized) is used as a marker (unsized)
pub fn run_scope<'bump>(&'bump mut self) -> Result<()> {
pub fn run_scope(&mut self) -> Result<()> {
// pub fn run_scope<'bump>(&'bump mut self) -> Result<()> {
let frame = {
let frame = self.frames.next();
frame.bump.reset();
@@ -92,7 +93,7 @@ impl Scope {
let node_slot = std::rc::Rc::new(RefCell::new(None));
let ctx: Context<'bump> = Context {
let ctx = Context {
arena: &self.hook_arena,
hooks: &self.hooks,
bump: &frame.bump,
@@ -107,7 +108,6 @@ impl Scope {
// todo!()
// Note that the actual modification of the vnode head element occurs during this call
let _: DomTree = (caller.as_ref())(ctx);
// let _: DomTree = (self.raw_caller)(ctx, &self.props);
/*
SAFETY ALERT
@@ -123,7 +123,6 @@ impl Scope {
frame.head_node = node_slot
.as_ref()
// .deref()
.borrow_mut()
.take()
.expect("Viewing did not happen");
+4 -24
View File
@@ -71,28 +71,16 @@ impl VirtualDom {
/// Performs a *full* rebuild of the virtual dom, returning every edit required to generate the actual dom.
pub fn rebuild<'s>(&'s mut self) -> Result<EditList<'s>> {
// Diff from the top
let mut diff_machine = DiffMachine::new(); // partial borrow
let mut diff_machine = DiffMachine::new();
let very_unsafe_components = &mut self.components as *mut generational_arena::Arena<Scope>;
let mut component = self
.components
.get_mut(self.base_scope)
.ok_or_else(|| Error::FatalInternal("Acquring base component should never fail"))?;
component.run_scope()?;
// let component = &*component;
diff_machine.diff_node(component.old_frame(), component.new_frame());
// get raw pointer to the arena
let very_unsafe_components = &mut self.components as *mut generational_arena::Arena<Scope>;
{
let component = self
.components
.get(self.base_scope)
.ok_or_else(|| Error::FatalInternal("Acquring base component should never fail"))?;
diff_machine.diff_node(component.old_frame(), component.new_frame());
}
// let p = &mut self.components;
// chew down the the lifecycle events until all dirty nodes are computed
while let Some(event) = diff_machine.lifecycle_events.pop_front() {
match event {
@@ -115,27 +103,19 @@ impl VirtualDom {
let real_scope = scope.upgrade().unwrap();
*real_scope.as_ref().borrow_mut() = Some(idx);
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 } => {
let idx = scope.upgrade().unwrap().as_ref().borrow().unwrap();
unsafe {
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();
c.update_caller(caller);
c.run_scope()?;
// c.caller = caller;
diff_machine.change_list.load_known_root(id);
diff_machine.diff_node(c.old_frame(), c.new_frame());
}
// break 'render;