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
42
43
44
45
46
47
48
49
50
51
52
use crate::app::dispatch::Dispatcher;
use crate::app::side_effect::{SideEffect, Commands};
use crate::app::detach::Detach;
use web_sys;
use wasm_bindgen::prelude::*;
use std::rc::Rc;
use std::cell::RefCell;
use std::fmt;
pub type ScheduledRender<Command> = (Vec<Command>, i32, Closure<dyn FnMut(f64)>);
pub trait Application<Message, Command> {
fn update(&mut self, msg: Message) -> Commands<Command>;
fn render(&mut self, app: &Dispatcher<Message, Command>) -> Vec<Command>;
fn process(&self, cmd: Command, app: &Dispatcher<Message, Command>);
fn get_scheduled_render(&mut self) -> &mut Option<ScheduledRender<Command>>;
fn set_scheduled_render(&mut self, handle: ScheduledRender<Command>);
fn push_listener(&mut self, listener: (String, Closure<dyn FnMut(web_sys::Event)>));
fn node(&self) -> Option<web_sys::Node>;
fn nodes(&self) -> Vec<web_sys::Node>;
fn create(&mut self, app: &Dispatcher<Message, Command>) -> Vec<web_sys::Node>;
fn detach(&mut self, app: &Dispatcher<Message, Command>);
}
impl<Message, Command> Detach<Message> for Rc<RefCell<Box<dyn Application<Message, Command>>>>
where
Message: fmt::Debug + Clone + PartialEq,
Command: SideEffect<Message>,
{
fn detach(&self) {
let mut app = self.borrow_mut();
Application::detach(&mut **app, &self.into());
}
}