Last active
July 22, 2020 18:57
-
-
Save willmtemple/0dc501733fb432394f086fa427659af1 to your computer and use it in GitHub Desktop.
RSX - HTML in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod utils; | |
use wasm_bindgen::prelude::*; | |
mod vdom; | |
use vdom::*; | |
mod dom; | |
use dom::mount; | |
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | |
// allocator. | |
#[cfg(feature = "wee_alloc")] | |
#[global_allocator] | |
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | |
fn nested_component() -> VDOM { | |
rsx!( | |
<p>"Hello, RSX!"</p> | |
) | |
} | |
fn my_component() -> VDOM { | |
rsx!( | |
<div class="application"> | |
<$nested_component /> | |
</div> | |
) | |
} | |
#[wasm_bindgen(start)] | |
pub fn main() { | |
utils::set_panic_hook(); | |
let window = web_sys::window().expect("could not get handle to 'window'"); | |
let document = window.document().expect("no 'document' on 'window'"); | |
let main_div = document.get_element_by_id("main").expect("no 'main' element on page"); | |
mount(rsx!( | |
<$my_component /> | |
), main_div); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment