Struct dioxus_core::UserEvent
source · [−]pub struct UserEvent {
pub scope_id: Option<ScopeId>,
pub priority: EventPriority,
pub element: Option<ElementId>,
pub name: &'static str,
pub data: Arc<dyn Any + Send + Sync>,
}Expand description
User Events are events that are shuttled from the renderer into the VirtualDom through the scheduler channel.
These events will be passed to the appropriate Element given by mounted_dom_id and then bubbled up through the tree
where each listener is checked and fired if the event name matches.
It is the expectation that the event name matches the corresponding event listener, otherwise Dioxus will panic in attempting to downcast the event data.
Because Event Data is sent across threads, it must be Send + Sync. We are hoping to lift the Sync restriction but
Send will not be lifted. The entire UserEvent must also be Send + Sync due to its use in the scheduler channel.
Example
fn App(cx: Scope) -> Element {
rsx!(cx, div {
onclick: move |_| println!("Clicked!")
})
}
let mut dom = VirtualDom::new(App);
let mut scheduler = dom.get_scheduler_channel();
scheduler.unbounded_send(SchedulerMsg::UiEvent(
UserEvent {
scope_id: None,
priority: EventPriority::Medium,
name: "click",
element: Some(ElementId(0)),
data: Arc::new(ClickEvent { .. })
}
)).unwrap();Fields
scope_id: Option<ScopeId>The originator of the event trigger if available
priority: EventPriorityThe priority of the event to be scheduled around ongoing work
element: Option<ElementId>The optional real node associated with the trigger
name: &'static strThe event type IE “onclick” or “onmouseover”
data: Arc<dyn Any + Send + Sync>The event data to be passed onto the event handler
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for UserEvent
impl Send for UserEvent
impl Sync for UserEvent
impl Unpin for UserEvent
impl !UnwindSafe for UserEvent
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more