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
use crate::EventAttribFn;
use std::borrow::Cow;
use std::rc::Rc;
use wasm_bindgen::convert::FromWasmAbi;
use wasm_bindgen::JsValue;
#[derive(Default)]
pub struct SpecialAttributes {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pub on_create_elem: Option<(Cow<'static, str>, EventAttribFn)>,
    
    
    pub dangerous_inner_html: Option<String>,
}
impl SpecialAttributes {
    
    pub fn maybe_call_on_create_elem(&self, element: &web_sys::Element) {
        #[cfg(target_arch = "wasm32")]
        if let Some(on_create_elem) = &self.on_create_elem {
            use wasm_bindgen::JsCast;
            let on_create_elem: &js_sys::Function =
                on_create_elem.1.as_ref().as_ref().unchecked_ref();
            on_create_elem
                .call1(&wasm_bindgen::JsValue::NULL, element)
                .unwrap();
        }
        let _ = element;
    }
}
impl PartialEq for SpecialAttributes {
    fn eq(&self, rhs: &Self) -> bool {
        self.dangerous_inner_html == rhs.dangerous_inner_html
    }
}
#[cfg(target_arch = "wasm32")]
pub fn wrap_closure<F: FnMut(T) + 'static, T: FromWasmAbi + 'static>(func: F) -> EventAttribFn {
    use wasm_bindgen::closure::Closure;
    let closure = Closure::wrap(Box::new(func) as Box<dyn FnMut(_)>);
    let closure_rc = std::rc::Rc::new(closure);
    EventAttribFn(closure_rc)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn wrap_closure<F: FnMut(T) + 'static, T: FromWasmAbi + 'static>(_func: F) -> EventAttribFn {
    EventAttribFn(Rc::new(JsValue::NULL))
}