rename HasProps to ComponentFunction

This commit is contained in:
Evan Almloff committed 2024-01-11 15:53:14 -06:00
1 parent 3267ddec10
commit 598b557aee
3 files changed
+11 -9

No files matched your search

+3 -3
View File
@@ -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<P: 'static, Phantom: 'static> {
pub render_fn: Rc<dyn HasProps<Phantom, Props = P>>,
pub render_fn: Rc<dyn ComponentFunction<Phantom, Props = P>>,
pub memo: fn(&P, &P) -> bool,
pub props: P,
pub name: &'static str,
@@ -47,7 +47,7 @@ pub(crate) struct VProps<P: 'static, Phantom: 'static> {
impl<P: 'static, Phantom: 'static> VProps<P, Phantom> {
pub(crate) fn new(
render_fn: impl HasProps<Phantom, Props = P> + 'static,
render_fn: impl ComponentFunction<Phantom, Props = P> + 'static,
memo: fn(&P, &P) -> bool,
props: P,
name: &'static str,
+2 -2
View File
@@ -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<Props<'_>>) -> Element;
/// ```
pub fn new<F: HasProps<P> + 'static, P: 'static>(
pub fn new<F: ComponentFunction<P> + 'static, P: 'static>(
component: F,
props: F::Props,
fn_name: &'static str,
+6 -4
View File
@@ -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<F: HasProps<P>, P>(_: F) -> <<F as HasProps<P>>::Props as Properties>::Builder
pub fn fc_to_builder<F: ComponentFunction<P>, P>(
_: F,
) -> <<F as ComponentFunction<P>>::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<P> {
pub trait ComponentFunction<P> {
type Props: 'static;
fn call(&self, props: Self::Props) -> Element;
}
impl<T: 'static, F: Fn(T) -> Element> HasProps<(T,)> for F {
impl<T: 'static, F: Fn(T) -> Element> ComponentFunction<(T,)> for F {
type Props = T;
fn call(&self, props: T) -> Element {
@@ -91,7 +93,7 @@ impl<T: 'static, F: Fn(T) -> Element> HasProps<(T,)> for F {
#[doc(hidden)]
pub struct ZeroElementMarker;
impl<F: Fn() -> Element> HasProps<ZeroElementMarker> for F {
impl<F: Fn() -> Element> ComponentFunction<ZeroElementMarker> for F {
type Props = ();
fn call(&self, _: ()) -> Element {