wip: pass more events
This commit is contained in:
1 parent
47d0f51e00
commit
0dad91bc08
20 files changed
+773
-31
No files matched your search
@@ -1,4 +1,7 @@
|
||||
use std::{cell::Cell, fmt::Arguments};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
fmt::Arguments,
|
||||
};
|
||||
|
||||
use bumpalo::boxed::Box as BumpBox;
|
||||
use bumpalo::Bump;
|
||||
@@ -7,7 +10,7 @@ use std::future::Future;
|
||||
use crate::{
|
||||
any_props::{AnyProps, VComponentProps},
|
||||
arena::ElementId,
|
||||
innerlude::DynamicNode,
|
||||
innerlude::{DynamicNode, EventHandler},
|
||||
Attribute, AttributeValue, Element, LazyNodes, Properties, Scope, ScopeState, VNode,
|
||||
};
|
||||
|
||||
@@ -106,6 +109,14 @@ impl ScopeState {
|
||||
scope: Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`EventHandler`] from an [`FnMut`]
|
||||
pub fn event_handler<'a, T>(&'a self, f: impl FnMut(T) + 'a) -> EventHandler<'a, T> {
|
||||
let handler: &mut dyn FnMut(T) = self.bump().alloc(f);
|
||||
let caller = unsafe { BumpBox::from_raw(handler as *mut dyn FnMut(T)) };
|
||||
let callback = RefCell::new(Some(caller));
|
||||
EventHandler { callback }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ComponentReturn<'a, A = ()> {
|
||||
|
||||
Reference in new issue
Block a user