@@ -4,32 +4,49 @@ use std::fmt;
44use std::iter;
55use std::mem;
66
7−/// A node is either a text node or an element.
7+/// A virtual DOM node.
88#[derive(Debug, Clone)]
9−pub enum Node<'a> {
10− /// A text node.
11− Text(TextNode<'a>),
9+pub struct Node<'a> {
10+ #[cfg(feature = "xxx-unstable-internal-use-only")]
11+ #[doc(hidden)]
12+ pub kind: NodeKind<'a>,
1213
13− /// An element potentially with attributes and children.
14− Element(ElementNode<'a>),
14+ #[cfg(not(feature = "xxx-unstable-internal-use-only"))]
15+ pub(crate) kind: NodeKind<'a>,
1516}
1617
17−/// Text nodes are just a string of text. They cannot have attributes or
18−/// children.
19−#[derive(Debug, Clone)]
20−pub struct TextNode<'a> {
21− pub(crate) text: &'a str,
18+pub_unstable_internal! {
19+ /// A node is either a text node or an element.
20+ #[derive(Debug, Clone)]
21+ pub(crate) enum NodeKind<'a> {
22+ /// A text node.
23+ Text(TextNode<'a>),
24+
25+ /// An element potentially with attributes and children.
26+ Element(ElementNode<'a>),
27+ }
2228}
2329
24−/// Elements have a tag name, zero or more attributes, and zero or more
25−/// children.
26−#[derive(Debug, Clone)]
27−pub struct ElementNode<'a> {
28− pub(crate) tag_name: &'a str,
29− pub(crate) listeners: &'a [Listener<'a>],
30− pub(crate) attributes: &'a [Attribute<'a>],
31− pub(crate) children: &'a [Node<'a>],
32− pub(crate) namespace: Option<&'a str>,
30+pub_unstable_internal! {
31+ /// Text nodes are just a string of text. They cannot have attributes or
32+ /// children.
33+ #[derive(Debug, Clone)]
34+ pub(crate) struct TextNode<'a> {
35+ pub text: &'a str,
36+ }
37+}
38+
39+pub_unstable_internal! {
40+ /// Elements have a tag name, zero or more attributes, and zero or more
41+ /// children.
42+ #[derive(Debug, Clone)]
43+ pub(crate) struct ElementNode<'a> {
44+ pub tag_name: &'a str,
45+ pub listeners: &'a [Listener<'a>],
46+ pub attributes: &'a [Attribute<'a>],
47+ pub children: &'a [Node<'a>],
48+ pub namespace: Option<&'a str>,
49+ }
3350}
3451
3552/// An event listener callback function.
@@ -39,7 +56,7 @@ pub struct ElementNode<'a> {
3956/// 1. The virtual DOM's root rendering component.
4057/// 2. A capability to scheduler virtual DOM re-rendering.
4158/// 3. The event that occurred.
42−pub type ListenerCallback<'a> =
59+pub(crate) type ListenerCallback<'a> =
4360 &'a (dyn Fn(&mut dyn RootRender, VdomWeak, web_sys::Event) + 'static);
4461
4562/// An event listener.
@@ -121,35 +138,23 @@ impl<'a> Node<'a> {
121138 let attributes: &'a Attributes = bump.alloc(attributes);
122139 let attributes: &'a [Attribute<'a>] = attributes.as_ref();
123140
124− Node::Element(ElementNode {
125− tag_name,
126− listeners,
127− attributes,
128− children,
129− namespace,
130− })
131− }
132−
133− /// Is this node a text node?
134− pub fn is_text(&self) -> bool {
135− match self {
136− Node::Text(_) => true,
137− _ => false,
138− }
139− }
140−
141− /// Is this node an element?
142− pub fn is_element(&self) -> bool {
143− match self {
144− Node::Element { .. } => true,
145− _ => false,
141+ Node {
142+ kind: NodeKind::Element(ElementNode {
143+ tag_name,
144+ listeners,
145+ attributes,
146+ children,
147+ namespace,
148+ }),
146149 }
147150 }
148151
149152 /// Construct a new text node with the given text.
150153 #[inline]
151154 pub(crate) fn text(text: &'a str) -> Node<'a> {
152− Node::Text(TextNode { text })
155+ Node {
156+ kind: NodeKind::Text(TextNode { text }),
157+ }
153158 }
154159}
155160
@@ -169,35 +174,6 @@ impl<'a> IntoIterator for Node<'a> {
169174 }
170175}
171176
172−impl<'a> TextNode<'a> {
173− /// Get this text node's text content.
174− pub fn text(&self) -> &'a str {
175− self.text
176− }
177−}
178−
179−impl<'a> ElementNode<'a> {
180− /// Get this element's tag name.
181− pub fn tag_name(&self) -> &'a str {
182− self.tag_name
183− }
184−
185− /// Get this element's attributes.
186− pub fn attributes(&self) -> &'a [Attribute<'a>] {
187− self.attributes
188− }
189−
190− /// Get this element's attributes.
191− pub fn children(&self) -> &'a [Node<'a>] {
192− self.children
193− }
194−
195− /// Get this element's namespace.
196− pub fn namespace(&self) -> Option<&'a str> {
197− self.namespace
198− }
199−}
200−
201177union CallbackFatPtr<'a> {
202178 callback: ListenerCallback<'a>,
203179 parts: (u32, u32),