65fbac1f74648e59af4ac5402b6854123e215183
4 use wasm_bindgen
::prelude
::*;
7 // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
9 #[cfg(feature = "wee_alloc")]
11 static ALLOC
: wee_alloc
::WeeAlloc
= wee_alloc
::WeeAlloc
::INIT
;
19 pub fn greet(name
: &str) {
20 alert(&format!("Hello, {}!", name
));
21 console
::log_1(&"Hello bg".into());
24 #[wasm_bindgen(start)]
25 pub fn main() -> Result
<(), JsValue
> {
26 console_error_panic_hook
::set_once();
28 let window
= web_sys
::window().expect("no global `window` exists");
29 let document
= window
.document().expect("should have a document on window");
30 //let body = document.body().expect("document should have a body");
32 let location
= window
.location().pathname()?
;
33 let path
: Vec
<&str> = location
.split('
/'
).skip(1).collect();
37 * [ok] get url (/recipe/edit/{id}) and extract the id
38 * - Add a handle (event?) to the title field (when edited/changed?):
39 * - Call (as AJAR) /ron-api/set-title and set the body to a serialized RON of the type common::ron_api::SetTitle
40 * - Display error message if needed
44 ["recipe", "edit", id
] => {
45 let id
= id
.parse
::<i64>().unwrap(); // TODO: remove unwrap.
46 console_log!("recipe edit ID: {}", id
);
48 handles
::edit_recipe(&document
);
50 let title_input
= document
.get_element_by_id("title_field").unwrap();
58 // let val = document.create_element("p")?;
59 // val.set_inner_html("Hello from Rust!");
60 // body.append_child(&val)?;