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
use crate::{document, Element};
use leptos_reactive::Scope;
use wasm_bindgen::UnwrapThrowExt;
pub trait Mountable {
    fn mount(&self, parent: &web_sys::Element);
}
impl Mountable for Element {
    fn mount(&self, parent: &web_sys::Element) {
        parent.append_child(self).unwrap_throw();
    }
}
impl Mountable for Vec<Element> {
    fn mount(&self, parent: &web_sys::Element) {
        for element in self {
            parent.append_child(element).unwrap_throw();
        }
    }
}
pub fn mount_to_body<T, F>(f: F)
where
    F: Fn(Scope) -> T + 'static,
    T: Mountable,
{
    mount(document().body().unwrap_throw(), f)
}
pub fn mount<T, F>(parent: web_sys::HtmlElement, f: F)
where
    F: Fn(Scope) -> T + 'static,
    T: Mountable,
{
    use leptos_reactive::create_scope;
    let _ = create_scope(move |cx| {
        (f(cx)).mount(&parent);
    });
}
#[cfg(feature = "hydrate")]
pub fn hydrate<T, F>(parent: web_sys::HtmlElement, f: F)
where
    F: Fn(Scope) -> T + 'static,
    T: Mountable,
{
    let _ = leptos_reactive::create_scope(move |cx| {
        cx.start_hydration(&parent);
        (f(cx));
        cx.end_hydration();
    });
}