From 598b557aee118271c97a232a3420e6ac54e8fa2a Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 11 Jan 2024 15:53:14 -0600 Subject: [PATCH] rename HasProps to ComponentFunction --- packages/core/src/any_props.rs | 6 +++--- packages/core/src/nodes.rs | 4 ++-- packages/core/src/properties.rs | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/core/src/any_props.rs b/packages/core/src/any_props.rs index 8046868bb..9c3c34cfe 100644 --- a/packages/core/src/any_props.rs +++ b/packages/core/src/any_props.rs @@ -1,4 +1,4 @@ -use crate::{nodes::RenderReturn, properties::HasProps}; +use crate::{nodes::RenderReturn, properties::ComponentFunction}; use std::{any::Any, ops::Deref, panic::AssertUnwindSafe, rc::Rc}; /// A boxed version of AnyProps that can be cloned @@ -39,7 +39,7 @@ pub(crate) trait AnyProps { } pub(crate) struct VProps { - pub render_fn: Rc>, + pub render_fn: Rc>, pub memo: fn(&P, &P) -> bool, pub props: P, pub name: &'static str, @@ -47,7 +47,7 @@ pub(crate) struct VProps { impl VProps { pub(crate) fn new( - render_fn: impl HasProps + 'static, + render_fn: impl ComponentFunction + 'static, memo: fn(&P, &P) -> bool, props: P, name: &'static str, diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index b502cfc23..425749dbb 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -1,6 +1,6 @@ use crate::any_props::{BoxedAnyProps, VProps}; use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState}; -use crate::properties::HasProps; +use crate::properties::ComponentFunction; use crate::{arena::ElementId, Element, Event}; use crate::{Properties, VirtualDom}; use std::ops::Deref; @@ -464,7 +464,7 @@ impl VComponent { /// fn(Props) -> Element; /// async fn(Scope>) -> Element; /// ``` - pub fn new + 'static, P: 'static>( + pub fn new + 'static, P: 'static>( component: F, props: F::Props, fn_name: &'static str, diff --git a/packages/core/src/properties.rs b/packages/core/src/properties.rs index 3694ae676..86c0f8b83 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -67,7 +67,9 @@ impl EmptyBuilder { /// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern /// to initialize a component's props. -pub fn fc_to_builder, P>(_: F) -> <>::Props as Properties>::Builder +pub fn fc_to_builder, P>( + _: F, +) -> <>::Props as Properties>::Builder where F::Props: Properties, { @@ -75,13 +77,13 @@ where } /// A function pointer that can be used to create a component. -pub trait HasProps

{ +pub trait ComponentFunction

{ type Props: 'static; fn call(&self, props: Self::Props) -> Element; } -impl Element> HasProps<(T,)> for F { +impl Element> ComponentFunction<(T,)> for F { type Props = T; fn call(&self, props: T) -> Element { @@ -91,7 +93,7 @@ impl Element> HasProps<(T,)> for F { #[doc(hidden)] pub struct ZeroElementMarker; -impl Element> HasProps for F { +impl Element> ComponentFunction for F { type Props = (); fn call(&self, _: ()) -> Element {