diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index 8894dbace..73b38dec9 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -7,6 +7,7 @@ on: - 'auto' - 'try' pull_request: + types: [opened, synchronize, reopened, ready_for_review] branches: - 'master' schedule: diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index b7057fbcc..a5b33f6b1 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -3,10 +3,6 @@ use std::{ rc::Rc, }; -use futures_util::Future; - -use crate::ScopeState; - /// A wrapper around some generic data that handles the event's state /// /// @@ -111,21 +107,6 @@ impl std::fmt::Debug for Event { } #[doc(hidden)] -pub trait EventReturn

: Sized { - fn spawn(self, _cx: &ScopeState) {} -} - -impl EventReturn<()> for () {} - -pub struct AsyncMarker; -impl EventReturn for T -where - T: Future + 'static, -{ - fn spawn(self, cx: &ScopeState) { - cx.spawn(self); - } -} /// The callback type generated by the `rsx!` macro when an `on` field is specified for components. /// diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 4fd8e4a8a..304197dab 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -71,10 +71,10 @@ pub(crate) mod innerlude { pub use crate::innerlude::{ fc_to_builder, AnyValue, Attribute, AttributeValue, BorrowedAttributeValue, CapturedError, - Component, DynamicNode, Element, ElementId, Event, EventReturn, Fragment, IntoDynNode, - LazyNodes, Mutation, Mutations, Properties, RenderReturn, Scope, ScopeId, ScopeState, Scoped, - SuspenseContext, TaskId, Template, TemplateAttribute, TemplateNode, VComponent, VNode, - VPlaceholder, VText, VirtualDom, + Component, DynamicNode, Element, ElementId, Event, Fragment, IntoDynNode, LazyNodes, Mutation, + Mutations, Properties, RenderReturn, Scope, ScopeId, ScopeState, Scoped, SuspenseContext, + TaskId, Template, TemplateAttribute, TemplateNode, VComponent, VNode, VPlaceholder, VText, + VirtualDom, }; /// The purpose of this module is to alleviate imports of many common types diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index 201e1d424..fceaefec6 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -7,7 +7,7 @@ use crate::{ innerlude::{ErrorBoundary, Scheduler, SchedulerMsg}, lazynodes::LazyNodes, nodes::{ComponentReturn, IntoAttributeValue, IntoDynNode, RenderReturn}, - AnyValue, Attribute, AttributeValue, Element, Event, EventReturn, Properties, TaskId, + AnyValue, Attribute, AttributeValue, Element, Event, Properties, TaskId, }; use bumpalo::{boxed::Box as BumpBox, Bump}; use bumpslab::{BumpSlab, Slot}; @@ -581,9 +581,9 @@ impl<'src> ScopeState { /// Create a new [`AttributeValue`] with the listener variant from a callback /// /// The callback must be confined to the lifetime of the ScopeState - pub fn listener>( + pub fn listener( &'src self, - mut callback: impl FnMut(Event) -> E + 'src, + mut callback: impl FnMut(Event) + 'src, ) -> AttributeValue<'src> { // safety: there's no other way to create a dynamicly-dispatched bump box other than alloc + from-raw // This is the suggested way to build a bumpbox @@ -595,8 +595,7 @@ impl<'src> ScopeState { callback(Event { propagates: event.propagates, data, - }) - .spawn(self); + }); } })) }; diff --git a/packages/html/src/events.rs b/packages/html/src/events.rs index 604c3a955..853400c28 100644 --- a/packages/html/src/events.rs +++ b/packages/html/src/events.rs @@ -8,10 +8,13 @@ macro_rules! impl_event { ) => { $( $( #[$attr] )* - pub fn $name<'a, E: ::dioxus_core::EventReturn, T>(_cx: &'a ::dioxus_core::ScopeState, _f: impl FnMut(::dioxus_core::Event<$data>) -> E + 'a) -> ::dioxus_core::Attribute<'a> { + #[inline] + pub fn $name<'a, E: crate::EventReturn, T>(_cx: &'a ::dioxus_core::ScopeState, mut _f: impl FnMut(::dioxus_core::Event<$data>) -> E + 'a) -> ::dioxus_core::Attribute<'a> { ::dioxus_core::Attribute { name: stringify!($name), - value: _cx.listener(_f), + value: _cx.listener(move |e: ::dioxus_core::Event<$data>| { + _f(e).spawn(_cx); + }), namespace: None, mounted_element: Default::default(), volatile: false, @@ -144,3 +147,24 @@ pub fn event_bubbles(evt: &str) -> bool { _ => true, } } + +use std::future::Future; + +#[doc(hidden)] +pub trait EventReturn

: Sized { + fn spawn(self, _cx: &dioxus_core::ScopeState) {} +} + +impl EventReturn<()> for () {} +#[doc(hidden)] +pub struct AsyncMarker; + +impl EventReturn for T +where + T: Future + 'static, +{ + #[inline] + fn spawn(self, cx: &dioxus_core::ScopeState) { + cx.spawn(self); + } +}