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
32
33
34
35
36
37
38
39
40
41
#[cfg(feature = "message-like-elm")]
mod app_with_message_like_elm;
#[cfg(feature = "message-like-elm")]
use app_with_message_like_elm as app;

#[cfg(not(feature = "message-like-elm"))]
mod app;

pub mod dom;
pub mod events;
#[macro_use]
pub mod macros;

use wasm_bindgen::UnwrapThrowExt;

pub mod prelude {
    pub use crate::app::*;
    pub use crate::dom::traits::*;

    pub use crate::dom::{ HasChildren, Node };
    pub use simi_macros::simi_app;
}

pub fn window() -> web_sys::Window {
    web_sys::window().expect_throw("web_sys::window()")
}

pub fn document() -> web_sys::Document {
    crate::window().document().expect_throw("crate::window().document()")
}


#[cfg(feature = "message-like-elm")]
pub fn interval<A, F>(ms: u32, main: &crate::app::WeakMain<A>, handler: F) -> timers::callback::Interval 
where 
    A: crate::app::Application,
    F: Fn() -> A::Message + 'static
{
    let main = main.clone();
    timers::callback::Interval::new(ms, move || main.send_message(handler()))
}