Add frontend tests and other stuff
[recipes.git] / frontend / src / lib.rs
1 mod utils;
2
3 use wasm_bindgen::prelude::*;
4 use web_sys::console;
5
6 // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
7 // allocator.
8 #[cfg(feature = "wee_alloc")]
9 #[global_allocator]
10 static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
11
12 #[wasm_bindgen]
13 extern {
14 fn alert(s: &str);
15 }
16
17 #[wasm_bindgen]
18 pub fn greet(name: &str) {
19 alert(&format!("Hello, {}!", name));
20 console::log_1(&"Hello bg".into());
21 }
22
23 #[wasm_bindgen(start)]
24 pub fn main() -> Result<(), JsValue> {
25 let window = web_sys::window().expect("no global `window` exists");
26 let document = window.document().expect("should have a document on window");
27 let body = document.body().expect("document should have a body");
28
29 let val = document.create_element("p")?;
30 val.set_inner_html("Hello from Rust!");
31
32 body.append_child(&val)?;
33
34 Ok(())
35 }