maomi: a rust framework for building pages with components
This is the DOM binding module of the framework.
Quick Start
Pages are composed by components.
To build a page, write a component which contains the page content.
use wasm_bindgen::prelude::*;
use maomi::prelude::*;
use maomi_dom::{prelude::*, element::*};
#[component(Backend = DomBackend)]
struct HelloWorld {
template: template! {
<div>
"Hello world!"
</div>
},
}
impl Component for HelloWorld {
fn new() -> Self {
Self {
template: Default::default(),
}
}
}
#[wasm_bindgen(start)]
pub fn wasm_main() {
let dom_backend = DomBackend::new_with_document_body().unwrap();
let backend_context = maomi::BackendContext::new(dom_backend);
let mount_point = backend_context
.enter_sync(move |ctx| {
ctx.attach(|_: &mut HelloWorld| {}).unwrap()
})
.map_err(|_| "Cannot init mount point")
.unwrap();
std::mem::forget(mount_point);
std::mem::forget(backend_context);
}