sauron_core/dom/program/
mount_procedure.rs

1/// specify how the App is mounted to the DOM
2#[derive(Clone, Copy)]
3pub enum MountAction {
4    /// append the APP's root node to the target mount node
5    Append,
6    /// clear any children of the target mount node then append the APP's root node
7    ClearAppend,
8    /// replace the target mount node with the APP's root node
9    Replace,
10}
11
12/// specify whether to attach the Node in shadow_root
13#[derive(Clone, Copy)]
14pub enum MountTarget {
15    /// attached in the mount node
16    MountNode,
17    /// attached to the shadow root
18    ShadowRoot,
19}
20
21/// specify how the root node will be mounted to the mount node
22#[derive(Clone, Copy)]
23pub struct MountProcedure {
24    /// instruction for mounting the app to the mount node
25    pub action: MountAction,
26    /// specify which part of the mount_node to attached to
27    pub target: MountTarget,
28}
29
30impl MountProcedure {
31    /// mount procedure with specified action and target
32    pub fn new(action: MountAction, target: MountTarget) -> Self {
33        Self { action, target }
34    }
35
36    /// append to the mount node
37    pub fn append() -> Self {
38        Self::new(MountAction::Append, MountTarget::MountNode)
39    }
40
41    /// clear the mount node before appending
42    pub fn clear_append() -> Self {
43        Self::new(MountAction::ClearAppend, MountTarget::MountNode)
44    }
45
46    /// replace the mount node
47    pub fn replace() -> Self {
48        Self::new(MountAction::Replace, MountTarget::MountNode)
49    }
50
51    /// append to the mount node but on it's shadow
52    pub fn append_to_shadow() -> Self {
53        Self::new(MountAction::Append, MountTarget::ShadowRoot)
54    }
55}
56
57impl Default for MountProcedure {
58    fn default() -> Self {
59        Self {
60            action: MountAction::Append,
61            target: MountTarget::MountNode,
62        }
63    }
64}