1use super::*;
2
3pub trait Component: Display + Sized + 'static {
4 fn name() -> &'static str;
5
6 async fn initialize() -> Result<Self, JsValue>;
7
8 fn define() {
9 js::define(
10 Self::name(),
11 &wasm_bindgen_futures::future_to_promise(Self::callback()),
12 );
13 }
14
15 async fn callback() -> Result<JsValue, JsValue> {
16 let component = Self::initialize().await?;
17
18 let parser = DomParser::new().unwrap();
19 let html = component.to_string();
20 let document = parser
21 .parse_from_string(&html, SupportedType::TextHtml)
22 .unwrap();
23
24 let callback = Closure::once(move |root| Self::connected(&Arc::new(component), root));
25
26 let array = Array::new();
27
28 array.push(&document.into());
29 array.push(&callback.into_js_value());
30
31 Ok(array.into())
32 }
33
34 fn connected(self: &Arc<Self>, _root: ShadowRoot) {}
35}