docs: better document the EventHandler type
This commit is contained in:
1 parent
5cacf91381
commit
be9f1a52ad
1 file changed
+24
-1
@@ -324,7 +324,30 @@ type InternalListenerCallback<'bump> = BumpBox<'bump, dyn FnMut(AnyEvent) + 'bum
|
|||||||
|
|
||||||
type ExternalListenerCallback<'bump, T> = BumpBox<'bump, dyn FnMut(T) + 'bump>;
|
type ExternalListenerCallback<'bump, T> = BumpBox<'bump, dyn FnMut(T) + 'bump>;
|
||||||
|
|
||||||
/// The callback based through the `rsx!` macro.
|
/// The callback type generated by the `rsx!` macro when an `on` field is specified for components.
|
||||||
|
///
|
||||||
|
/// This makes it possible to pass `move |evt| {}` style closures into components as property fields.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
///
|
||||||
|
/// rsx!{
|
||||||
|
/// MyComponent { onclick: move |evt| log::info!("clicked"), }
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// #[derive(Props)]
|
||||||
|
/// struct MyProps<'a> {
|
||||||
|
/// onclick: EventHandler<'a, MouseEvent>,
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn MyComponent(cx: Scope<'a, MyProps<'a>>) -> Element {
|
||||||
|
/// cx.render(rsx!{
|
||||||
|
/// button {
|
||||||
|
/// onclick: move |evt| cx.props.onclick.call(evt),
|
||||||
|
/// }
|
||||||
|
/// })
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
pub struct EventHandler<'bump, T = ()> {
|
pub struct EventHandler<'bump, T = ()> {
|
||||||
pub callback: &'bump RefCell<Option<ExternalListenerCallback<'bump, T>>>,
|
pub callback: &'bump RefCell<Option<ExternalListenerCallback<'bump, T>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user