Fix: some stuff related to event listeners. POC for lifecyel
This commit is contained in:
1 parent
4e48e0514e
commit
5b7887d76c
6 files changed
+103
-24
No files matched your search
@@ -146,13 +146,17 @@ pub struct EditMachine<'lock> {
|
||||
pub traversal: Traversal,
|
||||
next_temporary: u32,
|
||||
forcing_new_listeners: bool,
|
||||
|
||||
|
||||
// // if the current node is a "known" node
|
||||
// // any actions that modify this node should update the mapping
|
||||
// current_known: Option<u32>,
|
||||
pub emitter: EditList<'lock>,
|
||||
}
|
||||
|
||||
impl<'lock> EditMachine<'lock> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
// current_known: None,
|
||||
traversal: Traversal::new(),
|
||||
next_temporary: 0,
|
||||
forcing_new_listeners: false,
|
||||
@@ -283,6 +287,11 @@ impl<'a> EditMachine<'a> {
|
||||
debug_assert!(self.traversal_is_committed());
|
||||
// debug!("emit: replace_with()");
|
||||
self.emitter.push(Edit::ReplaceWith {});
|
||||
// if let Some(id) = self.current_known {
|
||||
// // update mapping
|
||||
// self.emitter.push(Edit::MakeKnown{node: id});
|
||||
// self.current_known = None;
|
||||
// }
|
||||
// self.emitter.replace_with();
|
||||
}
|
||||
|
||||
@@ -377,6 +386,7 @@ impl<'a> EditMachine<'a> {
|
||||
|
||||
pub fn load_known_root(&mut self, id: u32) {
|
||||
log::debug!("emit: TraverseToKnown({:?})", id);
|
||||
// self.current_known = Some(id);
|
||||
self.emitter.push(Edit::TraverseToKnown { node: id })
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,12 @@ impl Scope {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_caller<'creator_node>(&mut self, caller: Weak<OpaqueComponent<'creator_node>>) {
|
||||
let broken_caller: Weak<OpaqueComponent<'static>> = unsafe { std::mem::transmute(caller) };
|
||||
|
||||
self.caller = broken_caller;
|
||||
}
|
||||
|
||||
/// Create a new context and run the component with references from the Virtual Dom
|
||||
/// This function downcasts the function pointer based on the stored props_type
|
||||
///
|
||||
@@ -115,13 +121,14 @@ impl Scope {
|
||||
- Public API cannot drop or destructure VNode
|
||||
*/
|
||||
|
||||
frame.head_node = node_slot.as_ref()
|
||||
frame.head_node = node_slot
|
||||
.as_ref()
|
||||
// .deref()
|
||||
.borrow_mut()
|
||||
.take()
|
||||
.expect("Viewing did not happen");
|
||||
|
||||
Ok(())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// A safe wrapper around calling listeners
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::{error::Error, innerlude::*};
|
||||
use crate::{patch::Edit, scope::Scope};
|
||||
use generational_arena::Arena;
|
||||
use std::{any::TypeId, borrow::Borrow, rc::{Rc, Weak}};
|
||||
use std::{any::TypeId, borrow::{Borrow, BorrowMut}, rc::{Rc, Weak}};
|
||||
use thiserror::private::AsDynError;
|
||||
|
||||
// We actually allocate the properties for components in their parent's properties
|
||||
@@ -119,21 +119,20 @@ impl VirtualDom {
|
||||
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);
|
||||
// diff_machine.change_list.save_known_root(id);
|
||||
}
|
||||
}
|
||||
LifeCycleEvent::PropsChanged { caller, id, scope } => {
|
||||
let idx = scope.upgrade().unwrap().as_ref().borrow().unwrap();
|
||||
|
||||
// We're modifying the component arena while holding onto references into the assoiated bump arenas of its children
|
||||
// those references are stable, even if the component arena moves around in memory, thanks to the bump arenas.
|
||||
// However, there is no way to convey this to rust, so we need to use unsafe to pierce through the lifetime.
|
||||
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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user