1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use sycamore_reactive::untrack;
use crate::generic_node::GenericNode;
use crate::prelude::View;
pub trait Component<G: GenericNode> {
const NAME: &'static str = "UnnamedComponent";
type Props;
fn create_component(props: Self::Props) -> View<G>;
}
#[inline(always)]
pub fn instantiate_component<G: GenericNode, C: Component<G>>(props: C::Props) -> View<G> {
if G::USE_HYDRATION_CONTEXT {
#[cfg(feature = "experimental-hydrate")]
return crate::utils::hydrate::hydrate_component(|| untrack(|| C::create_component(props)));
#[cfg(not(feature = "experimental-hydrate"))]
return untrack(|| C::create_component(props));
} else {
untrack(|| C::create_component(props))
}
}
#[doc(hidden)]
pub trait __InstantiateComponent<G: GenericNode>: Component<G> {
#[doc(hidden)]
fn __instantiate_component(props: Self::Props) -> View<G>;
}
impl<C, G> __InstantiateComponent<G> for C
where
C: Component<G>,
G: GenericNode,
{
#[inline(always)]
fn __instantiate_component(props: Self::Props) -> View<G> {
instantiate_component::<G, C>(props)
}
}