Merge branch 'upstream' into simplify-native-core
This commit is contained in:
commit
ff408c17de
5 files changed
+35
-30
No files matched your search
@@ -7,6 +7,7 @@ on:
|
|||||||
- 'auto'
|
- 'auto'
|
||||||
- 'try'
|
- 'try'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, ready_for_review]
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
schedule:
|
schedule:
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ use std::{
|
|||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures_util::Future;
|
|
||||||
|
|
||||||
use crate::ScopeState;
|
|
||||||
|
|
||||||
/// A wrapper around some generic data that handles the event's state
|
/// A wrapper around some generic data that handles the event's state
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@@ -111,21 +107,6 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait EventReturn<P>: Sized {
|
|
||||||
fn spawn(self, _cx: &ScopeState) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventReturn<()> for () {}
|
|
||||||
|
|
||||||
pub struct AsyncMarker;
|
|
||||||
impl<T> EventReturn<AsyncMarker> for T
|
|
||||||
where
|
|
||||||
T: Future<Output = ()> + '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.
|
/// The callback type generated by the `rsx!` macro when an `on` field is specified for components.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ pub(crate) mod innerlude {
|
|||||||
|
|
||||||
pub use crate::innerlude::{
|
pub use crate::innerlude::{
|
||||||
fc_to_builder, AnyValue, Attribute, AttributeValue, BorrowedAttributeValue, CapturedError,
|
fc_to_builder, AnyValue, Attribute, AttributeValue, BorrowedAttributeValue, CapturedError,
|
||||||
Component, DynamicNode, Element, ElementId, Event, EventReturn, Fragment, IntoDynNode,
|
Component, DynamicNode, Element, ElementId, Event, Fragment, IntoDynNode, LazyNodes, Mutation,
|
||||||
LazyNodes, Mutation, Mutations, Properties, RenderReturn, Scope, ScopeId, ScopeState, Scoped,
|
Mutations, Properties, RenderReturn, Scope, ScopeId, ScopeState, Scoped, SuspenseContext,
|
||||||
SuspenseContext, TaskId, Template, TemplateAttribute, TemplateNode, VComponent, VNode,
|
TaskId, Template, TemplateAttribute, TemplateNode, VComponent, VNode, VPlaceholder, VText,
|
||||||
VPlaceholder, VText, VirtualDom,
|
VirtualDom,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The purpose of this module is to alleviate imports of many common types
|
/// The purpose of this module is to alleviate imports of many common types
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::{
|
|||||||
innerlude::{ErrorBoundary, Scheduler, SchedulerMsg},
|
innerlude::{ErrorBoundary, Scheduler, SchedulerMsg},
|
||||||
lazynodes::LazyNodes,
|
lazynodes::LazyNodes,
|
||||||
nodes::{ComponentReturn, IntoAttributeValue, IntoDynNode, RenderReturn},
|
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 bumpalo::{boxed::Box as BumpBox, Bump};
|
||||||
use bumpslab::{BumpSlab, Slot};
|
use bumpslab::{BumpSlab, Slot};
|
||||||
@@ -581,9 +581,9 @@ impl<'src> ScopeState {
|
|||||||
/// Create a new [`AttributeValue`] with the listener variant from a callback
|
/// Create a new [`AttributeValue`] with the listener variant from a callback
|
||||||
///
|
///
|
||||||
/// The callback must be confined to the lifetime of the ScopeState
|
/// The callback must be confined to the lifetime of the ScopeState
|
||||||
pub fn listener<T: 'static, P, E: EventReturn<P>>(
|
pub fn listener<T: 'static>(
|
||||||
&'src self,
|
&'src self,
|
||||||
mut callback: impl FnMut(Event<T>) -> E + 'src,
|
mut callback: impl FnMut(Event<T>) + 'src,
|
||||||
) -> AttributeValue<'src> {
|
) -> AttributeValue<'src> {
|
||||||
// safety: there's no other way to create a dynamicly-dispatched bump box other than alloc + from-raw
|
// 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
|
// This is the suggested way to build a bumpbox
|
||||||
@@ -595,8 +595,7 @@ impl<'src> ScopeState {
|
|||||||
callback(Event {
|
callback(Event {
|
||||||
propagates: event.propagates,
|
propagates: event.propagates,
|
||||||
data,
|
data,
|
||||||
})
|
});
|
||||||
.spawn(self);
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ macro_rules! impl_event {
|
|||||||
) => {
|
) => {
|
||||||
$(
|
$(
|
||||||
$( #[$attr] )*
|
$( #[$attr] )*
|
||||||
pub fn $name<'a, E: ::dioxus_core::EventReturn<T>, 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>, T>(_cx: &'a ::dioxus_core::ScopeState, mut _f: impl FnMut(::dioxus_core::Event<$data>) -> E + 'a) -> ::dioxus_core::Attribute<'a> {
|
||||||
::dioxus_core::Attribute {
|
::dioxus_core::Attribute {
|
||||||
name: stringify!($name),
|
name: stringify!($name),
|
||||||
value: _cx.listener(_f),
|
value: _cx.listener(move |e: ::dioxus_core::Event<$data>| {
|
||||||
|
_f(e).spawn(_cx);
|
||||||
|
}),
|
||||||
namespace: None,
|
namespace: None,
|
||||||
mounted_element: Default::default(),
|
mounted_element: Default::default(),
|
||||||
volatile: false,
|
volatile: false,
|
||||||
@@ -144,3 +147,24 @@ pub fn event_bubbles(evt: &str) -> bool {
|
|||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub trait EventReturn<P>: Sized {
|
||||||
|
fn spawn(self, _cx: &dioxus_core::ScopeState) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventReturn<()> for () {}
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub struct AsyncMarker;
|
||||||
|
|
||||||
|
impl<T> EventReturn<AsyncMarker> for T
|
||||||
|
where
|
||||||
|
T: Future<Output = ()> + 'static,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn spawn(self, cx: &dioxus_core::ScopeState) {
|
||||||
|
cx.spawn(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user