Skip to content

Commit

Permalink
Don't allocate event names
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 24, 2024
1 parent 668d338 commit f63e08c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/dioxus-blitz/src/documents/dioxus_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl DocumentLike for DioxusDocument {
// let data = dioxus::html::EventData::Mouse()

let data = Rc::new(PlatformEventData::new(Box::new(NativeClickData {})));
self.vdom.handle_event("click", data, id, true);
self.vdom.handle_event(event.name(), data, id, true);
return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {
// If we hit a node, then we collect the node to its parents, check for listeners, and then
// call those listeners
self.dom.handle_event(RendererEvent {
name: "click".to_string(),
target: node_id,
data: EventData::Click {
x: self.mouse_pos.0 as f64,
Expand Down
17 changes: 16 additions & 1 deletion packages/dom/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@ pub struct EventListener {
}

pub struct RendererEvent {
pub name: String,
pub target: usize,
pub data: EventData,
}

impl RendererEvent {
/// Returns the name of the event ("click", "mouseover", "keypress", etc)
pub fn name(&self) -> &'static str {
self.data.name()
}
}

pub enum EventData {
Click { x: f64, y: f64 },
Hover,
}

impl EventData {
pub fn name(&self) -> &'static str {
match self {
EventData::Click { .. } => "click",
EventData::Hover => "mouseover",
}
}
}

pub struct HitResult {
/// The node_id of the node identified as the hit target
pub node_id: usize,
Expand Down

0 comments on commit f63e08c

Please sign in to comment.