Struct dioxus_core::UserEvent [−][src]
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 trhough 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
