This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on docs.rs.

yew/dom_bundle/
mod.rs

1//! Realizing a virtual dom on the actual DOM
2//!
3//! A bundle, borrowed from the mathematical meaning, is any structure over some base space.
4//! In our case, the base space is the virtual dom we're trying to render.
5//! In order to efficiently implement updates, and diffing, additional information has to be
6//! kept around. This information is carried in the bundle.
7
8use web_sys::Element;
9
10use crate::html::AnyScope;
11use crate::virtual_dom::VNode;
12
13mod bcomp;
14mod blist;
15mod bnode;
16mod bportal;
17mod braw;
18mod bsuspense;
19mod btag;
20mod btext;
21mod position;
22mod subtree_root;
23
24mod traits;
25mod utils;
26
27use bcomp::BComp;
28use blist::BList;
29use bnode::BNode;
30use bportal::BPortal;
31use braw::BRaw;
32use bsuspense::BSuspense;
33use btag::{BTag, Registry};
34use btext::BText;
35pub(crate) use position::{DomSlot, DynamicDomSlot};
36use subtree_root::EventDescriptor;
37pub use subtree_root::{set_event_bubbling, BSubtree};
38use traits::{Reconcilable, ReconcileTarget};
39use utils::test_log;
40
41/// A Bundle.
42///
43/// Each component holds a bundle that represents a realised layout, designated by a [VNode].
44///
45/// This is not to be confused with [BComp], which represents a component in the position of a
46/// bundle layout.
47#[derive(Debug)]
48pub(crate) struct Bundle(BNode);
49
50impl Bundle {
51    /// Creates a new bundle.
52    pub const fn new() -> Self {
53        Self(BNode::List(BList::new()))
54    }
55
56    /// Shifts the bundle into a different position.
57    pub fn shift(&self, next_parent: &Element, slot: DomSlot) {
58        self.0.shift(next_parent, slot);
59    }
60
61    /// Applies a virtual dom layout to current bundle.
62    pub fn reconcile(
63        &mut self,
64        root: &BSubtree,
65        parent_scope: &AnyScope,
66        parent: &Element,
67        slot: DomSlot,
68        next_node: VNode,
69    ) -> DomSlot {
70        next_node.reconcile_node(root, parent_scope, parent, slot, &mut self.0)
71    }
72
73    /// Detaches current bundle.
74    pub fn detach(self, root: &BSubtree, parent: &Element, parent_to_detach: bool) {
75        self.0.detach(root, parent, parent_to_detach);
76    }
77}
78
79#[cfg(feature = "hydration")]
80#[path = "."]
81mod feat_hydration {
82    pub(super) use super::traits::Hydratable;
83    pub(super) use super::utils::node_type_str;
84    #[path = "./fragment.rs"]
85    mod fragment;
86    pub(crate) use fragment::Fragment;
87
88    use super::*;
89    impl Bundle {
90        /// Creates a bundle by hydrating a virtual dom layout.
91        pub fn hydrate(
92            root: &BSubtree,
93            parent_scope: &AnyScope,
94            parent: &Element,
95            fragment: &mut Fragment,
96            node: VNode,
97        ) -> Self {
98            let bundle = node.hydrate(root, parent_scope, parent, fragment);
99            Self(bundle)
100        }
101    }
102}
103#[cfg(feature = "hydration")]
104pub(crate) use feat_hydration::*;