mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
Rename to component function
This commit is contained in:
parent
c94af9538b
commit
3fb7c359c2
6 changed files with 30 additions and 21 deletions
|
@ -75,7 +75,7 @@ pub(crate) mod innerlude {
|
||||||
|
|
||||||
pub use crate::innerlude::{
|
pub use crate::innerlude::{
|
||||||
fc_to_builder, generation, schedule_update, schedule_update_any, use_hook, vdom_is_rendering,
|
fc_to_builder, generation, schedule_update, schedule_update_any, use_hook, vdom_is_rendering,
|
||||||
AnyValue, Attribute, AttributeValue, BoxedContext, CapturedError, Component,
|
AnyValue, Attribute, AttributeValue, BoxedContext, CapturedError, Component, ComponentFunction,
|
||||||
CrossPlatformConfig, DynamicNode, Element, ElementId, Event, Fragment, HasAttributes,
|
CrossPlatformConfig, DynamicNode, Element, ElementId, Event, Fragment, HasAttributes,
|
||||||
IntoDynNode, Mutation, Mutations, NoOpMutations, PlatformBuilder, Properties, RenderReturn,
|
IntoDynNode, Mutation, Mutations, NoOpMutations, PlatformBuilder, Properties, RenderReturn,
|
||||||
ScopeId, ScopeState, Task, Template, TemplateAttribute, TemplateNode, VComponent, VNode,
|
ScopeId, ScopeState, Task, Template, TemplateAttribute, TemplateNode, VComponent, VNode,
|
||||||
|
@ -91,7 +91,7 @@ pub mod prelude {
|
||||||
has_context, needs_update, parent_scope, provide_context, provide_root_context,
|
has_context, needs_update, parent_scope, provide_context, provide_root_context,
|
||||||
remove_future, schedule_update, schedule_update_any, spawn, spawn_forever, suspend,
|
remove_future, schedule_update, schedule_update_any, spawn, spawn_forever, suspend,
|
||||||
try_consume_context, use_error_boundary, use_hook, AnyValue, Attribute, Component,
|
try_consume_context, use_error_boundary, use_hook, AnyValue, Attribute, Component,
|
||||||
ComponentFn, Element, ErrorBoundary, Event, EventHandler, Fragment, HasAttributes,
|
ComponentFunction, Element, ErrorBoundary, Event, EventHandler, Fragment, HasAttributes,
|
||||||
IntoAttributeValue, IntoDynNode, Properties, Runtime, RuntimeGuard, ScopeId, ScopeState,
|
IntoAttributeValue, IntoDynNode, Properties, Runtime, RuntimeGuard, ScopeId, ScopeState,
|
||||||
Task, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
|
Task, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
use crate::{arena::ElementId, Element, Event};
|
use crate::{arena::ElementId, Element, Event};
|
||||||
use crate::{
|
use crate::{
|
||||||
innerlude::{ElementRef, EventHandler, MountId},
|
innerlude::{ElementRef, EventHandler, MountId},
|
||||||
properties::ComponentFn,
|
properties::ComponentFunction,
|
||||||
};
|
};
|
||||||
use crate::{Properties, VirtualDom};
|
use crate::{Properties, VirtualDom};
|
||||||
use core::panic;
|
use core::panic;
|
||||||
|
@ -533,7 +533,11 @@ impl VComponent {
|
||||||
/// fn(Props) -> Element;
|
/// fn(Props) -> Element;
|
||||||
/// async fn(Scope<Props<'_>>) -> Element;
|
/// async fn(Scope<Props<'_>>) -> Element;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<P, M>(component: impl ComponentFn<P, M>, props: P, fn_name: &'static str) -> Self
|
pub fn new<P, M>(
|
||||||
|
component: impl ComponentFunction<P, M>,
|
||||||
|
props: P,
|
||||||
|
fn_name: &'static str,
|
||||||
|
) -> Self
|
||||||
where
|
where
|
||||||
// The properties must be valid until the next bump frame
|
// The properties must be valid until the next bump frame
|
||||||
P: Properties + 'static,
|
P: Properties + 'static,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use crate::{properties::ComponentFn, Component, VirtualDom};
|
use crate::{properties::ComponentFunction, Component, VirtualDom};
|
||||||
|
|
||||||
/// A boxed object that can be injected into a component's context.
|
/// A boxed object that can be injected into a component's context.
|
||||||
pub struct BoxedContext(Box<dyn ClonableAny>);
|
pub struct BoxedContext(Box<dyn ClonableAny>);
|
||||||
|
@ -52,12 +52,12 @@ pub struct CrossPlatformConfig<Props: Clone + 'static> {
|
||||||
impl<Props: Clone + 'static> CrossPlatformConfig<Props> {
|
impl<Props: Clone + 'static> CrossPlatformConfig<Props> {
|
||||||
/// Create a new cross-platform config.
|
/// Create a new cross-platform config.
|
||||||
pub fn new<M>(
|
pub fn new<M>(
|
||||||
component: impl ComponentFn<Props, M>,
|
component: impl ComponentFunction<Props, M>,
|
||||||
props: Props,
|
props: Props,
|
||||||
root_contexts: Vec<BoxedContext>,
|
root_contexts: Vec<BoxedContext>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
component: ComponentFn::as_component(std::rc::Rc::new(component)),
|
component: ComponentFunction::as_component(std::rc::Rc::new(component)),
|
||||||
props,
|
props,
|
||||||
root_contexts,
|
root_contexts,
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl EmptyBuilder {
|
||||||
|
|
||||||
/// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern
|
/// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern
|
||||||
/// to initialize a component's props.
|
/// to initialize a component's props.
|
||||||
pub fn fc_to_builder<P, M>(_: impl ComponentFn<P, M>) -> <P as Properties>::Builder
|
pub fn fc_to_builder<P, M>(_: impl ComponentFunction<P, M>) -> <P as Properties>::Builder
|
||||||
where
|
where
|
||||||
P: Properties,
|
P: Properties,
|
||||||
{
|
{
|
||||||
|
@ -62,20 +62,23 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Any component that implements the `ComponentFn` trait can be used as a component.
|
/// Any component that implements the `ComponentFn` trait can be used as a component.
|
||||||
pub trait ComponentFn<Props, Marker> {
|
pub trait ComponentFunction<Props, Marker> {
|
||||||
|
type Props;
|
||||||
/// Convert the component to a function that takes props and returns an element.
|
/// Convert the component to a function that takes props and returns an element.
|
||||||
fn as_component(self: Rc<Self>) -> Component<Props>;
|
fn as_component(self: Rc<Self>) -> Component<Props>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept pre-formed component render functions as components
|
/// Accept pre-formed component render functions as components
|
||||||
impl<P> ComponentFn<P, ()> for Component<P> {
|
impl<P> ComponentFunction<P, ()> for Component<P> {
|
||||||
|
type Props = P;
|
||||||
fn as_component(self: Rc<Self>) -> Component<P> {
|
fn as_component(self: Rc<Self>) -> Component<P> {
|
||||||
self.as_ref().clone()
|
self.as_ref().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept any callbacks that take props
|
/// Accept any callbacks that take props
|
||||||
impl<F: Fn(P) -> Element + 'static, P> ComponentFn<P, ()> for F {
|
impl<F: Fn(P) -> Element + 'static, P> ComponentFunction<P, ()> for F {
|
||||||
|
type Props = P;
|
||||||
fn as_component(self: Rc<Self>) -> Component<P> {
|
fn as_component(self: Rc<Self>) -> Component<P> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,8 @@ impl<F: Fn(P) -> Element + 'static, P> ComponentFn<P, ()> for F {
|
||||||
|
|
||||||
/// Accept any callbacks that take no props
|
/// Accept any callbacks that take no props
|
||||||
pub struct EmptyMarker;
|
pub struct EmptyMarker;
|
||||||
impl<F: Fn() -> Element + 'static> ComponentFn<(), EmptyMarker> for F {
|
impl<F: Fn() -> Element + 'static> ComponentFunction<(), EmptyMarker> for F {
|
||||||
|
type Props = ();
|
||||||
fn as_component(self: Rc<Self>) -> Rc<dyn Fn(()) -> Element> {
|
fn as_component(self: Rc<Self>) -> Rc<dyn Fn(()) -> Element> {
|
||||||
Rc::new(move |_| self())
|
Rc::new(move |_| self())
|
||||||
}
|
}
|
||||||
|
@ -98,7 +102,8 @@ fn it_works_maybe() {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
let callable: Rc<dyn ComponentFn<(), ()>> = Rc::new(test) as Rc<dyn ComponentFn<_, _>>;
|
let callable: Rc<dyn ComponentFunction<(), ()>> =
|
||||||
let callable2: Rc<dyn ComponentFn<(), EmptyMarker>> =
|
Rc::new(test) as Rc<dyn ComponentFunction<_, _>>;
|
||||||
Rc::new(test2) as Rc<dyn ComponentFn<_, _>>;
|
let callable2: Rc<dyn ComponentFunction<(), EmptyMarker>> =
|
||||||
|
Rc::new(test2) as Rc<dyn ComponentFunction<_, _>>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
nodes::RenderReturn,
|
nodes::RenderReturn,
|
||||||
nodes::{Template, TemplateId},
|
nodes::{Template, TemplateId},
|
||||||
properties::ComponentFn,
|
properties::ComponentFunction,
|
||||||
runtime::{Runtime, RuntimeGuard},
|
runtime::{Runtime, RuntimeGuard},
|
||||||
scopes::ScopeId,
|
scopes::ScopeId,
|
||||||
AttributeValue, BoxedContext, Element, Event, Mutations,
|
AttributeValue, BoxedContext, Element, Event, Mutations,
|
||||||
|
@ -269,7 +269,7 @@ impl VirtualDom {
|
||||||
/// let mutations = dom.rebuild();
|
/// let mutations = dom.rebuild();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new_with_props<P: Clone + 'static, M>(
|
pub fn new_with_props<P: Clone + 'static, M>(
|
||||||
root: impl ComponentFn<P, M>,
|
root: impl ComponentFunction<P, M>,
|
||||||
root_props: P,
|
root_props: P,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (tx, rx) = futures_channel::mpsc::unbounded();
|
let (tx, rx) = futures_channel::mpsc::unbounded();
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct LaunchBuilder<Props: Clone + 'static, Platform: PlatformBuilder<Props
|
||||||
// Default platform builder
|
// Default platform builder
|
||||||
impl<Props: Clone + 'static> LaunchBuilder<Props> {
|
impl<Props: Clone + 'static> LaunchBuilder<Props> {
|
||||||
/// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
/// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
|
||||||
pub fn new<M>(component: impl ComponentFn<Props, M>) -> Self
|
pub fn new<M>(component: impl ComponentFunction<Props, M>) -> Self
|
||||||
where
|
where
|
||||||
Props: Default,
|
Props: Default,
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@ type CurrentPlatform = dioxus_web::WebPlatform;
|
||||||
type CurrentPlatform = ();
|
type CurrentPlatform = ();
|
||||||
|
|
||||||
/// Launch your application without any additional configuration. See [`LaunchBuilder`] for more options.
|
/// Launch your application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||||
pub fn launch<Props, Marker>(component: impl ComponentFn<Props, Marker>)
|
pub fn launch<Props, Marker>(component: impl ComponentFunction<Props, Marker>)
|
||||||
where
|
where
|
||||||
Props: Default + Clone + 'static,
|
Props: Default + Clone + 'static,
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ where
|
||||||
|
|
||||||
#[cfg(feature = "web")]
|
#[cfg(feature = "web")]
|
||||||
/// Launch your web application without any additional configuration. See [`LaunchBuilder`] for more options.
|
/// Launch your web application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||||
pub fn launch_web<Props, Marker>(component: impl ComponentFn<Props, Marker>)
|
pub fn launch_web<Props, Marker>(component: impl ComponentFunction<Props, Marker>)
|
||||||
where
|
where
|
||||||
Props: Default + Clone + 'static,
|
Props: Default + Clone + 'static,
|
||||||
{
|
{
|
||||||
|
@ -115,7 +115,7 @@ where
|
||||||
|
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
/// Launch your desktop application without any additional configuration. See [`LaunchBuilder`] for more options.
|
/// Launch your desktop application without any additional configuration. See [`LaunchBuilder`] for more options.
|
||||||
pub fn launch_desktop<Props, Marker>(component: impl ComponentFn<Props, Marker>)
|
pub fn launch_desktop<Props, Marker>(component: impl ComponentFunction<Props, Marker>)
|
||||||
where
|
where
|
||||||
Props: Default + Clone + 'static,
|
Props: Default + Clone + 'static,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue