Recipe edit (WIP): all form fields are now saved
This commit is contained in:
parent
07b7ff425e
commit
6876a254e1
12 changed files with 563 additions and 210 deletions
|
|
@ -1,19 +1,59 @@
|
|||
// use web_sys::console;
|
||||
use gloo::utils::document;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::Element;
|
||||
|
||||
pub fn set_panic_hook() {
|
||||
// When the `console_error_panic_hook` feature is enabled, we can call the
|
||||
// `set_panic_hook` function at least once during initialization, and then
|
||||
// we will get better error messages if our code ever panics.
|
||||
//
|
||||
// For more details see
|
||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
||||
#[cfg(feature = "console_error_panic_hook")]
|
||||
console_error_panic_hook::set_once();
|
||||
pub trait SelectExt {
|
||||
fn select<T>(&self, selectors: &str) -> T
|
||||
where
|
||||
T: JsCast;
|
||||
}
|
||||
|
||||
// #[macro_export]
|
||||
// macro_rules! console_log {
|
||||
// // Note that this is using the `log` function imported above during
|
||||
// // `bare_bones`
|
||||
// ($($t:tt)*) => (console::log_1(&format_args!($($t)*).to_string().into()))
|
||||
// }
|
||||
impl SelectExt for Element {
|
||||
fn select<T>(&self, selectors: &str) -> T
|
||||
where
|
||||
T: JsCast,
|
||||
{
|
||||
self.query_selector(selectors)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.dyn_into::<T>()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select<T>(selectors: &str) -> T
|
||||
where
|
||||
T: JsCast,
|
||||
{
|
||||
document()
|
||||
.query_selector(selectors)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.dyn_into::<T>()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn select_and_clone<T>(selectors: &str) -> T
|
||||
where
|
||||
T: JsCast,
|
||||
{
|
||||
document()
|
||||
.query_selector(selectors)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.clone_node_with_deep(true)
|
||||
.unwrap()
|
||||
.dyn_into::<T>()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn by_id<T>(element_id: &str) -> T
|
||||
where
|
||||
T: JsCast,
|
||||
{
|
||||
document()
|
||||
.get_element_by_id(element_id)
|
||||
.unwrap()
|
||||
.dyn_into::<T>()
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue