Refactor WebEventExt (#2707)

* Create WebEventExt::try_as_web_event and refactor
* Inline and adjust error message
* Inline downcast methods
This commit is contained in:
Matt Hunzinger authored and GitHub committed 2024-07-31 13:01:25 -07:00
1 parent 63e7aab4e8
commit 4bf71111c8
17 files changed
+71 -42

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ impl AnimationData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_ref().as_any().downcast_ref::<T>()
}
+1
View File
@@ -33,6 +33,7 @@ impl ClipboardData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_ref().as_any().downcast_ref::<T>()
}
+1
View File
@@ -52,6 +52,7 @@ impl DragData {
}
/// Downcast this event data to a specific type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
HasDragData::as_any(&*self.inner).downcast_ref::<T>()
}
+1
View File
@@ -33,6 +33,7 @@ impl FocusData {
}
/// Downcast this event data to a specific type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -111,6 +111,7 @@ impl FormData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -83,6 +83,7 @@ impl KeyboardData {
}
/// Downcast this KeyboardData to a concrete type.
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -32,6 +32,7 @@ impl MediaData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+2 -1
View File
@@ -121,6 +121,7 @@ impl MountedData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
@@ -186,7 +187,7 @@ impl_event! [
/// id: "some-id",
/// onmounted: move |element| {
/// // You can use the web_event trait to downcast the element to a web specific event. For the mounted event, this will be a web_sys::Element
/// let web_sys_element = element.web_event();
/// let web_sys_element = element.as_web_event();
/// assert_eq!(web_sys_element.id(), "some-id");
/// }
/// }
+1
View File
@@ -113,6 +113,7 @@ impl MouseData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -17,6 +17,7 @@ impl PointerData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -21,6 +21,7 @@ impl ScrollData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -15,6 +15,7 @@ impl SelectionData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -33,6 +33,7 @@ impl ToggleData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+2
View File
@@ -56,6 +56,7 @@ impl TouchData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
@@ -213,6 +214,7 @@ impl TouchPoint {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -39,6 +39,7 @@ impl TransitionData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref::<T>()
}
+1
View File
@@ -54,6 +54,7 @@ impl WheelData {
}
/// Downcast this event to a concrete event type
#[inline(always)]
pub fn downcast<T: 'static>(&self) -> Option<&T> {
HasWheelData::as_any(&*self.inner).downcast_ref::<T>()
}