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
use std::cell::{Ref, RefCell};
use std::fmt;
use std::rc::Rc;

#[derive(Default, Debug, Clone)]
pub struct NodeRef<N: fmt::Debug> {
    node: Rc<RefCell<Option<N>>>,
}

impl<N: fmt::Debug> NodeRef<N> {
    pub fn new() -> Self {
        Self {
            node: Rc::new(RefCell::new(None)),
        }
    }
    pub fn get(&self) -> Ref<'_, Option<N>> {
        self.node.borrow()
    }
    pub fn set(&self, node: N) {
        let _ = self.node.borrow_mut().insert(node);
    }
}

#[cfg(all(target_arch = "wasm32", feature = "web-csr"))]
pub type Node = web_sys::Element;

cfg_feature! {
    #![not(all(target_arch = "wasm32", feature = "web-csr"))]
    mod ssr;
    pub use ssr::*;
}