-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlib.rs
31 lines (27 loc) · 1.23 KB
/
lib.rs
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
use wasm_bindgen::prelude::*;
// A Draco application is a struct (or enum) which stores its state.
// We declare a unit struct here because we don't have any state to store.
struct HelloWorld;
// A Draco application must implement the `draco::Application` trait.
impl draco::Application for HelloWorld {
// `Message` is the type of value our HTML will emit.
// Here we aren't emitting anything so we use the unit type.
// You can put any type here and this example will still compile.
type Message = ();
// The `view` function returns what we want to display on the page.
fn view(&self) -> draco::VNode<Self::Message> {
// `draco::html::h1()` creates an `<h1>` element.
draco::html::h1()
// `.with()` adds a child to the element. Here we add a Text Node by pushing a string.
.with("Hello, world!")
// We use `.into()` to convert an `Element` struct to a `Node` struct which this
// function must return.
.into()
}
}
#[wasm_bindgen(start)]
pub fn start() {
// We select the first element on the page matching the CSS selector `main` and start the
// application on it.
draco::start(HelloWorld, draco::select("main").expect("<main>").into());
}