rename HasProps to ComponentFunction
This commit is contained in:
1 parent
3267ddec10
commit
598b557aee
3 files changed
+11
-9
No files matched your search
@@ -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};
|
use std::{any::Any, ops::Deref, panic::AssertUnwindSafe, rc::Rc};
|
||||||
|
|
||||||
/// A boxed version of AnyProps that can be cloned
|
/// 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(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 memo: fn(&P, &P) -> bool,
|
||||||
pub props: P,
|
pub props: P,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
@@ -47,7 +47,7 @@ pub(crate) struct VProps<P: 'static, Phantom: 'static> {
|
|||||||
|
|
||||||
impl<P: 'static, Phantom: 'static> VProps<P, Phantom> {
|
impl<P: 'static, Phantom: 'static> VProps<P, Phantom> {
|
||||||
pub(crate) fn new(
|
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,
|
memo: fn(&P, &P) -> bool,
|
||||||
props: P,
|
props: P,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::any_props::{BoxedAnyProps, VProps};
|
use crate::any_props::{BoxedAnyProps, VProps};
|
||||||
use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState};
|
use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState};
|
||||||
use crate::properties::HasProps;
|
use crate::properties::ComponentFunction;
|
||||||
use crate::{arena::ElementId, Element, Event};
|
use crate::{arena::ElementId, Element, Event};
|
||||||
use crate::{Properties, VirtualDom};
|
use crate::{Properties, VirtualDom};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@@ -464,7 +464,7 @@ impl VComponent {
|
|||||||
/// fn(Props) -> Element;
|
/// fn(Props) -> Element;
|
||||||
/// async fn(Scope<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,
|
component: F,
|
||||||
props: F::Props,
|
props: F::Props,
|
||||||
fn_name: &'static str,
|
fn_name: &'static str,
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ 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<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
|
where
|
||||||
F::Props: Properties,
|
F::Props: Properties,
|
||||||
{
|
{
|
||||||
@@ -75,13 +77,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A function pointer that can be used to create a component.
|
/// A function pointer that can be used to create a component.
|
||||||
pub trait HasProps<P> {
|
pub trait ComponentFunction<P> {
|
||||||
type Props: 'static;
|
type Props: 'static;
|
||||||
|
|
||||||
fn call(&self, props: Self::Props) -> Element;
|
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;
|
type Props = T;
|
||||||
|
|
||||||
fn call(&self, props: T) -> Element {
|
fn call(&self, props: T) -> Element {
|
||||||
@@ -91,7 +93,7 @@ impl<T: 'static, F: Fn(T) -> Element> HasProps<(T,)> for F {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct ZeroElementMarker;
|
pub struct ZeroElementMarker;
|
||||||
impl<F: Fn() -> Element> HasProps<ZeroElementMarker> for F {
|
impl<F: Fn() -> Element> ComponentFunction<ZeroElementMarker> for F {
|
||||||
type Props = ();
|
type Props = ();
|
||||||
|
|
||||||
fn call(&self, _: ()) -> Element {
|
fn call(&self, _: ()) -> Element {
|
||||||
|
|||||||
Reference in new issue
Block a user