sauron_native/
program.rs

1use crate::{backend::Backend, Component, Node};
2use std::{cell::RefCell, fmt::Debug, marker::PhantomData, rc::Rc};
3
4/// Holds the app and the dom updater
5/// This is passed into the event listener and the dispatch program
6/// will be called after the event is triggered.
7pub struct Program<APP, MSG, B> {
8    backend: Rc<B>,
9    _phantom_data: PhantomData<MSG>,
10    _phantom_app: PhantomData<APP>,
11}
12
13impl<APP, MSG, B> Program<APP, MSG, B>
14where
15    MSG: Clone + Debug + 'static,
16    APP: Component<MSG> + 'static,
17    B: Backend<APP, MSG>,
18{
19    /// Create an Rc wrapped instance of program, initializing DomUpdater with the initial view
20    /// and root node, but doesn't mount it yet.
21    pub fn new(app: APP) -> Rc<Self> {
22        println!("Instantiation..");
23        let program = Program {
24            backend: B::init(app),
25            _phantom_data: PhantomData,
26            _phantom_app: PhantomData,
27        };
28        Rc::new(program)
29    }
30
31    /// This is called when an event is triggered in the html DOM.
32    pub fn dispatch(self: &Rc<Self>, msg: MSG) {
33        self.backend.start_render();
34    }
35}