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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use sycamore_reactive::*;
use crate::generic_node::GenericNode;
use crate::view::View;
#[doc(hidden)]
pub fn component_scope<G: GenericNode>(f: impl FnOnce() -> View<G>) -> View<G> {
if G::USE_HYDRATION_CONTEXT {
#[cfg(feature = "hydrate")]
return crate::hydrate::hydrate_component(|| untrack(f));
#[cfg(not(feature = "hydrate"))]
return untrack(f);
} else {
untrack(f)
}
}
pub trait Prop {
type Builder;
fn builder() -> Self::Builder;
}
#[doc(hidden)]
pub struct UnitBuilder;
impl UnitBuilder {
pub fn build(self) {}
}
impl Prop for () {
type Builder = UnitBuilder;
fn builder() -> Self::Builder {
UnitBuilder
}
}
#[doc(hidden)]
pub fn element_like_component_builder<'a, T: Prop + 'a, G: GenericNode>(
_f: &impl FnOnce(Scope<'a>, T) -> View<G>,
) -> T::Builder {
T::builder()
}
pub struct Children<'a, G: GenericNode> {
f: Box<dyn FnOnce(BoundedScope<'_, 'a>) -> View<G> + 'a>,
}
impl<'a, F, G: GenericNode> From<F> for Children<'a, G>
where
F: FnOnce(BoundedScope<'_, 'a>) -> View<G> + 'a,
{
fn from(f: F) -> Self {
Self { f: Box::new(f) }
}
}
impl<'a, G: GenericNode> Children<'a, G> {
pub fn call(self, cx: BoundedScope<'_, 'a>) -> View<G> {
(self.f)(cx)
}
pub fn call_with_bounded_scope(self, cx: BoundedScope<'_, 'a>) -> View<G> {
(self.f)(cx)
}
pub fn new(_cx: Scope<'a>, f: impl FnOnce(BoundedScope<'_, 'a>) -> View<G> + 'a) -> Self {
Self { f: Box::new(f) }
}
}