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
//! # Maple API Documentation
//!
//! Maple is a VDOM-less web library with fine-grained reactivity.
//!
//! This is the API docs for maple. If you are looking for the usage docs, checkout the [README](https://github.com/lukechu10/maple).
//!
//! ## Supported Targets
//! - `wasm32-unknown-unknown`

#[doc(hidden)]
pub mod internal;

pub mod reactive;

use web_sys::HtmlElement;

/// The result of the `template!` macro. Should not be used directly.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TemplateResult {
    element: HtmlElement,
}

/// Render an [`HtmlElement`] into the DOM.
pub fn render(template_result: TemplateResult) {
    let window = web_sys::window().unwrap();
    let document = window.document().unwrap();
    document
        .body()
        .unwrap()
        .append_child(&template_result.element)
        .unwrap();
}

impl TemplateResult {
    /// Create a new `TemplateResult` from an [`HtmlElement`].
    pub fn new(element: HtmlElement) -> Self {
        Self { element }
    }

    pub fn inner_element(&self) -> HtmlElement {
        self.element.clone()
    }
}

/// The maple prelude.
pub mod prelude {
    pub use crate::reactive::{
        create_effect, create_memo, create_selector, create_signal, untracked, SetStateHandle,
        StateHandle,
    };
    pub use crate::{render, TemplateResult};

    pub use maple_core_macro::template;
}