allow registering custom element and fix deadlock

This commit is contained in:
Evan Almloff 2023-04-08 19:01:48 -05:00
parent 60be849ff0
commit 500a73abae

View file

@ -10,7 +10,7 @@ use std::collections::VecDeque;
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, RwLock};
use crate::custom_element::{CustomElementManager, CustomElementRegistry};
use crate::custom_element::{CustomElement, CustomElementManager, CustomElementRegistry};
use crate::node::{
ElementNode, FromAnyValue, NodeType, OwnedAttributeDiscription, OwnedAttributeValue, TextNode,
};
@ -206,7 +206,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
if is_element {
let custom_elements = self.custom_elements.clone();
custom_elements
.write()
.read()
.unwrap()
.add_shadow_dom(NodeMut::new(id, self));
}
@ -426,6 +426,11 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
pub fn raw_world_mut(&mut self) -> &mut World {
&mut self.world
}
/// Registers a new custom element.
pub fn register_custom_element<E: CustomElement<V>>(&mut self) {
self.custom_elements.write().unwrap().register::<E>()
}
}
/// A reference to a tracked component in a node.