#![allow(unused_macros)]
use std::panic;
use wasm_bindgen::JsCast;
pub mod dom_types;
pub mod fetch;
#[macro_use]
pub mod shortcuts;
pub mod storage;
mod vdom;
mod websys_bridge;
#[macro_use]
extern crate serde_derive;
pub fn to_input(target: &web_sys::EventTarget ) -> &web_sys::HtmlInputElement {
target.dyn_ref::<web_sys::HtmlInputElement>().expect("Unable to cast as an input element")
}
pub fn to_textarea(target: &web_sys::EventTarget ) -> &web_sys::HtmlTextAreaElement {
target.dyn_ref::<web_sys::HtmlTextAreaElement>().expect("Unable to cast as a textarea element")
}
pub fn to_select(target: &web_sys::EventTarget ) -> &web_sys::HtmlSelectElement {
target.dyn_ref::<web_sys::HtmlSelectElement>().expect("Unable to cast as a select element")
}
pub fn to_kbevent(event: &web_sys::Event ) -> &web_sys::KeyboardEvent {
event.dyn_ref::<web_sys::KeyboardEvent>().expect("Unable to cast as a keyboard event")
}
pub fn run<Ms, Mdl>(model: Mdl, update: fn(Ms, Mdl) -> Mdl,
view: fn(Mdl) -> dom_types::El<Ms>, mount_point_id: &str)
where Ms: Clone + Sized + 'static, Mdl: Clone + Sized + 'static
{
let app = vdom::App::new(model.clone(), update, view, mount_point_id);
let mut topel_vdom = (app.data.view)(model);
app.setup_vdom(&mut topel_vdom, 0, 0);
vdom::attach_listeners(&mut topel_vdom, app.mailbox());
websys_bridge::attach_els(&mut topel_vdom, &app.data.mount_point);
app.data.main_el_vdom.replace(topel_vdom);
panic::set_hook(Box::new(console_error_panic_hook::hook));
}
pub fn empty<Ms: Clone>() -> dom_types::El<Ms> {
let mut el = dom_types::El::empty(dom_types::Tag::Del);
el.add_attr("dummy-element".into(), "true".into());
el
}
pub fn log<S: ToString>(text: S) {
web_sys::console::log_1(&text.to_string().into());
}
pub mod prelude {
pub use crate::dom_types::{El, UpdateEl, simple_ev, input_ev, keyboard_ev, raw_ev};
}