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
use crate::ExternRef;
use once_cell::sync::Lazy;
use spin::Mutex;
use std::collections::HashMap;

pub trait CustomElement {
    fn construct(&mut self, component_ref: ExternRef);
    fn connected_callback(&mut self);
    fn disconnected_callback(&mut self);
    fn adopted_callback(&mut self);
    fn attribute_changed_callback(
        &mut self,
        name: String,
        old_value: Option<String>,
        new_value: Option<String>,
    );
    fn observed_attributes(&self) -> Vec<&'static str> {
        vec![]
    }
}

static CUSTOM_COMPONENT_STATE: Lazy<Mutex<HashMap<i64, Box<dyn CustomElement + Send + Sync>>>> =
    Lazy::new(|| Mutex::new(HashMap::new()));

pub fn add_custom_component(id: i64, component: Box<dyn CustomElement + Send + Sync>) {
    let mut state = CUSTOM_COMPONENT_STATE.lock();
    state.insert(id, component);
}

pub fn remove_custom_component(id: i64) {
    let mut state = CUSTOM_COMPONENT_STATE.lock();
    state.remove(&id);
}

pub fn custom_element_define<T>(tag_name: &str)
where
    T: CustomElement + Into<ExternRef> + Default,
{
}