mod attribute;
mod decl;
mod event;
mod registry;
mod store;
pub(crate) mod ts;
#[cfg(test)]
mod apply_tests;
#[cfg(test)]
mod tests;
use std::cell::RefCell;
use std::sync::Arc;
pub use attribute::{AnyAttribute, AttrBinding, Attribute, animatable_binding};
pub use decl::{Common, Element, SpawnCtx, SpawnFn};
pub use event::{AnyElementEvent, ElementEvent, ElementEvents, EventSubscriptions, handler_prop};
pub use registry::ElementInfo;
pub(crate) use store::Entry;
pub use store::{AttrDirty, Attrs};
thread_local! {
static DECODE_ELEMENT: RefCell<Option<DecodeElement>> = const { RefCell::new(None) };
}
#[derive(Clone)]
pub(crate) enum DecodeElement {
Known(Arc<ElementInfo>),
Unknown,
}
pub struct DecodeScope {
previous: Option<DecodeElement>,
}
impl DecodeScope {
pub fn new(kind: &str) -> Self {
let element = crate::ext::with_thread_registry(|r| {
match r
.unwrap_or_else(|| crate::ext::core_registry())
.element_info(kind)
.cloned()
{
Some(info) => DecodeElement::Known(info),
None => DecodeElement::Unknown,
}
});
let previous = DECODE_ELEMENT.with(|e| e.borrow_mut().replace(element));
Self { previous }
}
}
impl Drop for DecodeScope {
fn drop(&mut self) {
let previous = self.previous.take();
DECODE_ELEMENT.with(|e| *e.borrow_mut() = previous);
}
}
pub(crate) fn decode_element() -> Option<DecodeElement> {
DECODE_ELEMENT.with(|e| e.borrow().clone())
}