consecuit/construction/
hole.rs

1use web_sys::Node;
2
3use crate::stores::StoresList;
4
5use super::component::ComponentConstruction;
6
7/// Marker trait used internally. Sealed.
8#[sealed::sealed]
9pub trait MaybeHoleNode: 'static + Clone {}
10#[derive(Clone)]
11
12/// Internal use.
13pub struct NoHoleNode;
14#[sealed::sealed]
15impl MaybeHoleNode for NoHoleNode {}
16#[derive(Clone)]
17
18/// Internal use.
19pub struct YesHoleNode(pub(crate) Node);
20#[sealed::sealed]
21impl MaybeHoleNode for YesHoleNode {}
22
23impl<Stores, EntireStores> ComponentConstruction<Stores, EntireStores, YesHoleNode, NoHoleNode>
24where
25    Stores: StoresList,
26    EntireStores: StoresList,
27{
28    /// Mark the lastest comp as the Hole of this component.
29    ///
30    /// Calling `.child(...)` on this component will put the children there.
31    ///
32    /// A component that returns `impl ContainerReturn` must have exactly one `.hole_here()`.
33    ///
34    /// The [`cc_tree!`][consecuit_macros::cc_tree] macro equivalent to this is the `HOLE` attribute. Like
35    /// `<div HOLE />`
36    pub fn hole_here(self) -> ComponentConstruction<Stores, EntireStores, NoHoleNode, YesHoleNode> {
37        let ComponentConstruction {
38            hook_stores,
39            parent_node,
40            last_node,
41            ..
42        } = self;
43        ComponentConstruction {
44            hook_stores,
45            parent_node,
46            last_node: NoHoleNode,
47            ret_node: last_node,
48        }
49    }
50}