use crate::context::Context;
use crate::element::Element;
use crate::types::ComponentId;
pub trait Component: Send + Sync + 'static {
fn build(&self, ctx: &mut Context) -> Element;
fn on_mount(&self) {}
fn on_unmount(&self) {}
fn type_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
fn into_element(self) -> Element
where
Self: Sized,
{
use crate::element::{ComponentElement, Element};
use std::sync::Arc;
Element::Component(ComponentElement {
id: ComponentId(0),
key: None,
component: Arc::new(self),
children: vec![],
})
}
}