sauron_core/dom/
application.rs

1use crate::dom::Cmd;
2use crate::vdom::Node;
3pub use skip_diff::{skip_if, SkipDiff, SkipPath};
4
5///
6pub mod skip_diff;
7
8/// An Application is the root component of your program.
9/// Everything that happens in your application is done here.
10///
11pub trait Application: Sized + 'static {
12    ///
13    type MSG;
14    ///  The application can implement this method where it can modify its initial state.
15    ///  This method is called right after the program is mounted into the DOM.
16    fn init(&mut self) -> Cmd<Self::MSG> {
17        Cmd::none()
18    }
19
20    /// Update the component with a message.
21    /// The update function returns a Dispatch, which can be executed by the runtime.
22    ///
23    /// Called each time an action is triggered from the view
24    fn update(&mut self, _msg: Self::MSG) -> Cmd<Self::MSG>;
25
26    /// Returns a node on how the component is presented.
27    fn view(&self) -> Node<Self::MSG>;
28
29    /// The css style for the application, will be mounted automatically by the program
30    fn stylesheet() -> Vec<String> {
31        vec![]
32    }
33
34    /// dynamic style of an application which will be reinjected when the application style changed
35    fn style(&self) -> Vec<String> {
36        vec![]
37    }
38
39    /// This is called after dispatching and updating the dom for the component
40    /// This is for diagnostic and performance measurement purposes.
41    ///
42    /// Warning: DO NOT use for anything else other than the intended purpose
43    fn measurements(&mut self, _measurements: Measurements) {}
44}
45
46/// Contains the time it took for the last app update call for the component
47/// TODO: Maybe rename to Diagnostics
48#[derive(Clone, Copy, Debug, PartialEq, Default)]
49pub struct Measurements {
50    /// The number of DOM nodes in this Component
51    pub node_count: usize,
52    /// Time it took for the Component to build it's view
53    pub build_view_took: f64,
54    /// Total number of patches applied on this update loop
55    pub total_patches: usize,
56    /// Time it took for the patching the DOM.
57    pub dom_update_took: f64,
58    /// Total time it took for the component dispatch
59    pub total_time: f64,
60    /// The total count reference of the Program App
61    pub strong_count: usize,
62    /// The total weak count reference of the Program App
63    pub weak_count: usize,
64}