浏览代码

Merge pull request #1795 from ealmloff/fix-ondoubleclick-merge

Jonathan Kelley 1 年之前
父节点
当前提交
cfbcef1b11
共有 2 个文件被更改,包括 11 次插入17 次删除
  1. 9 2
      packages/html/src/events.rs
  2. 2 15
      packages/html/src/events/mouse.rs

+ 9 - 2
packages/html/src/events.rs

@@ -6,7 +6,7 @@ macro_rules! impl_event {
         $data:ty;
         $(
             $( #[$attr:meta] )*
-            $name:ident
+            $name:ident $(: $js_name:literal)?
         )*
     ) => {
         $(
@@ -14,7 +14,7 @@ macro_rules! impl_event {
             #[inline]
             pub fn $name<'a, E: crate::EventReturn<T>, T>(_cx: &'a ::dioxus_core::ScopeState, mut _f: impl FnMut(::dioxus_core::Event<$data>) -> E + 'a) -> ::dioxus_core::Attribute<'a> {
                 ::dioxus_core::Attribute::new(
-                    stringify!($name),
+                    impl_event!(@name $name $($js_name)?),
                     _cx.listener(move |e: ::dioxus_core::Event<crate::PlatformEventData>| {
                         _f(e.map(|e|e.into())).spawn(_cx);
                     }),
@@ -24,6 +24,13 @@ macro_rules! impl_event {
             }
         )*
     };
+
+    (@name $name:ident $js_name:literal) => {
+        $js_name
+    };
+    (@name $name:ident) => {
+        stringify!($name)
+    };
 }
 
 static EVENT_CONVERTER: RwLock<Option<Box<dyn HtmlEventConverter>>> = RwLock::new(None);

+ 2 - 15
packages/html/src/events/mouse.rs

@@ -78,6 +78,8 @@ impl_event! {
     #[deprecated(since = "0.5.0", note = "use ondoubleclick instead")]
     ondblclick
 
+    ondoubleclick: "ondblclick"
+
     /// onmousedown
     onmousedown
 
@@ -102,21 +104,6 @@ impl_event! {
     onmouseup
 }
 
-/// ondoubleclick
-#[inline]
-pub fn ondoubleclick<'a, E: crate::EventReturn<T>, T>(
-    _cx: &'a ::dioxus_core::ScopeState,
-    mut _f: impl FnMut(::dioxus_core::Event<MouseData>) -> E + 'a,
-) -> ::dioxus_core::Attribute<'a> {
-    ::dioxus_core::Attribute::new(
-        "ondblclick",
-        _cx.listener(move |e: ::dioxus_core::Event<MouseData>| {
-            _f(e).spawn(_cx);
-        }),
-        None,
-        false,
-    )
-}
 
 impl MouseData {
     /// Create a new instance of MouseData