use super::*;
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct CustomElementRegistry {
inner: Any,
}
impl FromVal for CustomElementRegistry {
fn from_val(v: &Any) -> Self {
CustomElementRegistry {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for CustomElementRegistry {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for CustomElementRegistry {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for CustomElementRegistry {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for CustomElementRegistry {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<CustomElementRegistry> for Any {
fn from(s: CustomElementRegistry) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&CustomElementRegistry> for Any {
fn from(s: &CustomElementRegistry) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(CustomElementRegistry);
impl CustomElementRegistry {
pub fn new() -> CustomElementRegistry {
Self {
inner: Any::global("CustomElementRegistry").new(&[]).as_::<Any>(),
}
}
}
impl CustomElementRegistry {
pub fn define(&self, name: &JsString, constructor: &Function) -> Undefined {
self.inner
.call("define", &[name.into(), constructor.into()])
.as_::<Undefined>()
}
}
impl CustomElementRegistry {
pub fn define_with_options(
&self,
name: &JsString,
constructor: &Function,
options: &ElementDefinitionOptions,
) -> Undefined {
self.inner
.call("define", &[name.into(), constructor.into(), options.into()])
.as_::<Undefined>()
}
}
impl CustomElementRegistry {
pub fn get(&self, name: &JsString) -> Any {
self.inner.call("get", &[name.into()]).as_::<Any>()
}
}
impl CustomElementRegistry {
pub fn get_name(&self, constructor: &Function) -> JsString {
self.inner
.call("getName", &[constructor.into()])
.as_::<JsString>()
}
}
impl CustomElementRegistry {
pub fn when_defined(&self, name: &JsString) -> Promise<Function> {
self.inner
.call("whenDefined", &[name.into()])
.as_::<Promise<Function>>()
}
}
impl CustomElementRegistry {
pub fn upgrade(&self, root: &Node) -> Undefined {
self.inner
.call("upgrade", &[root.into()])
.as_::<Undefined>()
}
}
impl CustomElementRegistry {
pub fn initialize(&self, root: &Node) -> Undefined {
self.inner
.call("initialize", &[root.into()])
.as_::<Undefined>()
}
}