浏览代码

rename HasProps to ComponentFunction

Evan Almloff 1 年之前
父节点
当前提交
598b557aee
共有 3 个文件被更改,包括 11 次插入9 次删除
  1. 3 3
      packages/core/src/any_props.rs
  2. 2 2
      packages/core/src/nodes.rs
  3. 6 4
      packages/core/src/properties.rs

+ 3 - 3
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<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
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<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
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<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 {