-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
mod.rs
78 lines (66 loc) · 2.08 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Realizing a virtual dom on the actual DOM
//!
//! A bundle, borrowed from the mathematical meaning, is any structure over some base space.
//! In our case, the base space is the virtual dom we're trying to render.
//! In order to efficiently implement updates, and diffing, additional information has to be
//! kept around. This information is carried in the bundle.
mod bcomp;
mod blist;
mod bnode;
mod bportal;
mod bsuspense;
mod btag;
mod btext;
mod subtree_root;
mod traits;
mod utils;
use web_sys::Element;
use crate::html::AnyScope;
use crate::html::NodeRef;
use crate::virtual_dom::VNode;
use bcomp::BComp;
use blist::BList;
use bnode::BNode;
use bportal::BPortal;
use bsuspense::BSuspense;
use btag::{BTag, Registry};
use btext::BText;
use subtree_root::EventDescriptor;
use traits::{Reconcilable, ReconcileTarget};
use utils::{insert_node, test_log};
#[doc(hidden)] // Publically exported from crate::events
pub use subtree_root::set_event_bubbling;
pub(crate) use subtree_root::BSubtree;
/// A Bundle.
///
/// Each component holds a bundle that represents a realised layout, designated by a [VNode].
///
/// This is not to be confused with [BComp], which represents a component in the position of a
/// bundle layout.
#[derive(Debug)]
pub(crate) struct Bundle(BNode);
impl Bundle {
/// Creates a new bundle.
pub const fn new() -> Self {
Self(BNode::List(BList::new()))
}
/// Shifts the bundle into a different position.
pub fn shift(&self, next_parent: &Element, next_sibling: NodeRef) {
self.0.shift(next_parent, next_sibling);
}
/// Applies a virtual dom layout to current bundle.
pub fn reconcile(
&mut self,
root: &BSubtree,
parent_scope: &AnyScope,
parent: &Element,
next_sibling: NodeRef,
next_node: VNode,
) -> NodeRef {
next_node.reconcile_node(root, parent_scope, parent, next_sibling, &mut self.0)
}
/// Detaches current bundle.
pub fn detach(self, root: &BSubtree, parent: &Element, parent_to_detach: bool) {
self.0.detach(root, parent, parent_to_detach);
}
}