feat: wire up event delegator for webview
This commit is contained in:
1 parent
0a907b35c6
commit
7dfe89c958
21 files changed
+265
-272
No files matched your search
@@ -20,8 +20,7 @@ pub struct ElementId(pub usize);
|
||||
|
||||
impl ElementId {
|
||||
pub fn as_u64(self) -> u64 {
|
||||
todo!()
|
||||
// self.0.as_ffi()
|
||||
self.0 as u64
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ impl<'r, 'b> DiffMachine<'r, 'b> {
|
||||
pub fn get_scope_mut(&mut self, id: &ScopeId) -> Option<&'b mut Scope> {
|
||||
// ensure we haven't seen this scope before
|
||||
// if we have, then we're trying to alias it, which is not allowed
|
||||
debug_assert!(!self.seen_nodes.contains(id));
|
||||
// debug_assert!(!self.seen_nodes.contains(id));
|
||||
unsafe { self.vdom.get_scope_mut(*id) }
|
||||
}
|
||||
pub fn get_scope(&mut self, id: &ScopeId) -> Option<&'b Scope> {
|
||||
@@ -120,10 +120,11 @@ impl<'real, 'bump> DiffMachine<'real, 'bump> {
|
||||
//
|
||||
// each function call assumes the stack is fresh (empty).
|
||||
pub fn diff_node(&mut self, old_node: &'bump VNode<'bump>, new_node: &'bump VNode<'bump>) {
|
||||
let root = old_node
|
||||
.dom_id
|
||||
.get()
|
||||
.expect("Should not be diffing old nodes that were never assigned");
|
||||
// currently busted for components - need to fid
|
||||
let root = old_node.dom_id.get().expect(&format!(
|
||||
"Should not be diffing old nodes that were never assigned, {:#?}",
|
||||
old_node
|
||||
));
|
||||
|
||||
match (&old_node.kind, &new_node.kind) {
|
||||
// Handle the "sane" cases first.
|
||||
|
||||
@@ -125,6 +125,8 @@ pub enum VirtualEvent {
|
||||
hook_idx: usize,
|
||||
domnode: Rc<Cell<Option<ElementId>>>,
|
||||
},
|
||||
// TOOD: make garbage collection its own dedicated event
|
||||
// GarbageCollection {}
|
||||
}
|
||||
|
||||
pub mod on {
|
||||
@@ -183,6 +185,7 @@ pub mod on {
|
||||
where F: FnMut($wrapper) + 'a
|
||||
{
|
||||
let bump = &c.bump();
|
||||
|
||||
let cb: &mut dyn FnMut(VirtualEvent) = bump.alloc(move |evt: VirtualEvent| match evt {
|
||||
VirtualEvent::$wrapper(event) => callback(event),
|
||||
_ => unreachable!("Downcasted VirtualEvent to wrong event type - this is an internal bug!")
|
||||
@@ -190,8 +193,10 @@ pub mod on {
|
||||
|
||||
let callback: BumpBox<dyn FnMut(VirtualEvent) + 'a> = unsafe { BumpBox::from_raw(cb) };
|
||||
|
||||
let event_name = stringify!($name);
|
||||
let shortname: &'static str = &event_name[2..];
|
||||
Listener {
|
||||
event: stringify!($name),
|
||||
event: shortname,
|
||||
mounted_node: Cell::new(None),
|
||||
scope: c.scope.our_arena_idx,
|
||||
callback: RefCell::new(callback),
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
//!
|
||||
|
||||
pub use crate::innerlude::{
|
||||
format_args_f, html, rsx, Context, DioxusElement, DomEdit, DomTree, ElementId, EventTrigger,
|
||||
LazyNodes, NodeFactory, Properties, RealDom, ScopeId, VNode, VNodeKind, VirtualDom,
|
||||
VirtualEvent, FC,
|
||||
format_args_f, html, rsx, Context, DioxusElement, DomEdit, DomTree, ElementId, EventPriority,
|
||||
EventTrigger, LazyNodes, NodeFactory, Properties, RealDom, ScopeId, VNode, VNodeKind,
|
||||
VirtualDom, VirtualEvent, FC,
|
||||
};
|
||||
|
||||
pub mod prelude {
|
||||
|
||||
@@ -249,13 +249,12 @@ impl<'a> NodeFactory<'a> {
|
||||
|
||||
// We take the references directly from the bump arena
|
||||
//
|
||||
//
|
||||
// TODO: this code shouldn't necessarily be here of all places
|
||||
// It would make more sense to do this in diffing
|
||||
|
||||
let mut queue = self.scope.listeners.borrow_mut();
|
||||
for listener in listeners.iter() {
|
||||
let long_listener: &Listener<'static> = unsafe { std::mem::transmute(listener) };
|
||||
let long_listener: &'a Listener<'static> = unsafe { std::mem::transmute(listener) };
|
||||
queue.push(long_listener as *const _)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ impl Scope {
|
||||
let next_frame = self.frames.prev_frame_mut();
|
||||
next_frame.bump.reset();
|
||||
|
||||
// make sure we call the drop implementation on all the listeners
|
||||
// this is important to not leak memory
|
||||
self.listeners.borrow_mut().clear();
|
||||
|
||||
unsafe { self.hooks.reset() };
|
||||
|
||||
@@ -258,10 +258,10 @@ impl VirtualDom {
|
||||
// but the guarantees provide a safe, fast, and efficient abstraction for the VirtualDOM updating framework.
|
||||
//
|
||||
// A good project would be to remove all unsafe from this crate and move the unsafety into safer abstractions.
|
||||
pub async fn progress_with_event<'s>(
|
||||
pub async fn progress_with_event<'a, 's>(
|
||||
&'s mut self,
|
||||
realdom: &'s mut dyn RealDom<'s>,
|
||||
edits: &mut Vec<DomEdit<'s>>,
|
||||
realdom: &'a mut dyn RealDom<'s>,
|
||||
edits: &'a mut Vec<DomEdit<'s>>,
|
||||
) -> Result<()> {
|
||||
let trigger = self.triggers.borrow_mut().pop().expect("failed");
|
||||
|
||||
|
||||
Reference in new issue
Block a user