fix components that take no arguments
This commit is contained in:
1 parent
404c864246
commit
1794debf79
24 files changed
+98
-78
No files matched your search
@@ -139,7 +139,7 @@ impl ErrorBoundary {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// #[component]
|
||||
/// fn App(cx: Scope, count: String) -> Element {
|
||||
/// fn App( count: String) -> Element {
|
||||
/// let id: i32 = count.parse().throw()?;
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
@@ -164,7 +164,7 @@ pub trait Throw<S = ()>: Sized {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// #[component]
|
||||
/// fn App(cx: Scope, count: String) -> Element {
|
||||
/// fn App( count: String) -> Element {
|
||||
/// let id: i32 = count.parse().throw()?;
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
@@ -187,7 +187,7 @@ pub trait Throw<S = ()>: Sized {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// #[component]
|
||||
/// fn App(cx: Scope, count: String) -> Element {
|
||||
/// fn App( count: String) -> Element {
|
||||
/// let id: i32 = count.parse().throw()?;
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
|
||||
@@ -145,10 +145,10 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
|
||||
/// onclick: EventHandler<'a, MouseEvent>,
|
||||
/// }
|
||||
///
|
||||
/// fn MyComponent(cx: Scope<'a, MyProps<'a>>) -> Element {
|
||||
/// fn MyComponent(cx: MyProps) -> Element {
|
||||
/// cx.render(rsx!{
|
||||
/// button {
|
||||
/// onclick: move |evt| cx.props.onclick.call(evt),
|
||||
/// onclick: move |evt| cx.onclick.call(evt),
|
||||
/// }
|
||||
/// })
|
||||
/// }
|
||||
|
||||
@@ -80,7 +80,7 @@ impl<const A: bool> FragmentBuilder<A> {
|
||||
/// cx.render(rsx!{
|
||||
/// div {
|
||||
/// h1 {"Title card"}
|
||||
/// {cx.props.children}
|
||||
/// {cx.children}
|
||||
/// }
|
||||
/// })
|
||||
/// }
|
||||
|
||||
@@ -67,8 +67,39 @@ 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<T: Properties>(_: fn(T) -> Element) -> T::Builder {
|
||||
T::builder()
|
||||
pub fn fc_to_builder<F: HasProps<P>, P>(
|
||||
_: F,
|
||||
) -> <<F as HasProps<P>>::Props as Properties>::Builder {
|
||||
F::Props::builder()
|
||||
}
|
||||
|
||||
/// A function pointer that can be used to create a component.
|
||||
pub trait HasProps<P> {
|
||||
type Props: Properties;
|
||||
}
|
||||
|
||||
impl<T: Properties, F: Fn(T) -> Element> HasProps<(T,)> for F {
|
||||
type Props = T;
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct ZeroElementMarker;
|
||||
impl<F: Fn() -> Element> HasProps<ZeroElementMarker> for F {
|
||||
type Props = ();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_builder() {
|
||||
fn app() -> Element {
|
||||
render!(div {})
|
||||
}
|
||||
fn app2(_: ()) -> Element {
|
||||
render!(div {})
|
||||
}
|
||||
let builder = fc_to_builder(app);
|
||||
builder.build();
|
||||
let builder = fc_to_builder(app2);
|
||||
builder.build();
|
||||
}
|
||||
|
||||
#[cfg(not(miri))]
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Runtime {
|
||||
/// }
|
||||
///
|
||||
/// fn Component(cx: Scope<ComponentProps>) -> Element {
|
||||
/// cx.use_hook(|| RuntimeGuard::new(cx.props.runtime.clone()));
|
||||
/// cx.use_hook(|| RuntimeGuard::new(cx.runtime.clone()));
|
||||
///
|
||||
/// render! { div {} }
|
||||
/// }
|
||||
|
||||
@@ -36,7 +36,7 @@ use std::{any::Any, cell::Cell, collections::BTreeSet, future::Future, rc::Rc};
|
||||
///
|
||||
/// fn App(cx: Scope<AppProps>) -> Element {
|
||||
/// cx.render(rsx!(
|
||||
/// div {"hello, {cx.props.title}"}
|
||||
/// div {"hello, {cx.title}"}
|
||||
/// ))
|
||||
/// }
|
||||
/// ```
|
||||
@@ -58,25 +58,25 @@ use std::{any::Any, cell::Cell, collections::BTreeSet, future::Future, rc::Rc};
|
||||
/// fn App(cx: Scope<AppProps>) -> Element {
|
||||
/// cx.render(rsx!(
|
||||
/// NavBar { routes: ROUTES }
|
||||
/// Title { "{cx.props.title}" }
|
||||
/// Title { "{cx.title}" }
|
||||
/// Footer {}
|
||||
/// ))
|
||||
/// }
|
||||
///
|
||||
/// #[component]
|
||||
/// fn NavBar(cx: Scope, routes: &'static str) -> Element {
|
||||
/// fn NavBar( routes: &'static str) -> Element {
|
||||
/// cx.render(rsx! {
|
||||
/// div { "Routes: {routes}" }
|
||||
/// })
|
||||
/// }
|
||||
///
|
||||
/// #[component]
|
||||
/// fn Footer(cx: Scope) -> Element {
|
||||
/// fn Footer() -> Element {
|
||||
/// cx.render(rsx! { div { "Footer" } })
|
||||
/// }
|
||||
///
|
||||
/// #[component]
|
||||
/// fn Title<'a>(cx: Scope<'a>, children: Element) -> Element {
|
||||
/// fn Title<'a>( children: Element) -> Element {
|
||||
/// cx.render(rsx! {
|
||||
/// div { id: "title", children }
|
||||
/// })
|
||||
@@ -218,7 +218,7 @@ impl VirtualDom {
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust, ignore
|
||||
/// fn Example(cx: Scope) -> Element {
|
||||
/// fn Example() -> Element {
|
||||
/// cx.render(rsx!( div { "hello world" } ))
|
||||
/// }
|
||||
///
|
||||
@@ -248,7 +248,7 @@ impl VirtualDom {
|
||||
/// }
|
||||
///
|
||||
/// fn Example(cx: Scope<SomeProps>) -> Element {
|
||||
/// cx.render(rsx!{ div{ "hello {cx.props.name}" } })
|
||||
/// cx.render(rsx!{ div{ "hello {cx.name}" } })
|
||||
/// }
|
||||
///
|
||||
/// let dom = VirtualDom::new(Example);
|
||||
|
||||
Reference in new issue
Block a user