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
use std::rc::Rc;
use wasm_bindgen::JsValue;
use super::{AnyNodeValue, Node};
#[derive(Debug, Clone)]
pub enum AnyNode {
Null,
Value(AnyNodeValue),
Element(crate::Element),
Multiple(Rc<Vec<crate::Keyed<crate::Element>>>),
}
impl AnyNode {
#[inline]
pub fn null() -> Self {
Self::Null
}
#[inline]
pub(crate) fn unsafe_into_js_node_value(self) -> JsValue {
let js = match self {
AnyNode::Null => JsValue::NULL,
AnyNode::Value(v) => v.into(),
AnyNode::Element(el) => el.unsafe_into_js_element().into(),
AnyNode::Multiple(els) => (match Rc::try_unwrap(els) {
Ok(els) => js_sys::Array::from_iter(
els.into_iter()
.map(|node| node.0.into_node().unsafe_into_js_node_value()),
),
Err(els) => js_sys::Array::from_iter(
els.iter()
.map(|node| node.0.to_node().unsafe_into_js_node_value()),
),
})
.into(),
};
js
}
}