use super::*;
pub trait Lifecycle {
fn retention_policy(&self) -> PageRetention {
PageRetention::Freeze
}
fn on_create(&self) {}
fn on_mount(&self, _node: NodeId) {}
fn on_update(&self, _node: NodeId) {}
fn on_activate(&self, _node: NodeId) {}
fn on_freeze(&self, _node: NodeId) {}
fn on_resume(&self, _node: NodeId) {}
fn on_unmount(&self, _node: NodeId) {}
fn on_destroy(&self) {}
fn on_error(&self, _error: &str) {}
fn on_appear(&self) {}
fn on_disappear(&self) {}
fn on_foreground(&self) {}
fn on_background(&self) {}
fn on_inactive(&self) {}
fn on_terminate(&self) {}
fn on_system_event(&self, _event: &SystemEvent) {}
}
pub trait Component: Lifecycle + Sized + 'static {
fn render(&self) -> NodeId;
fn mount(self) -> NodeId {
let instance: Rc<Self> = Rc::new(self);
instance.on_create();
let node: NodeId = instance.render();
let hooks: Rc<dyn Lifecycle> = Rc::clone(&instance) as Rc<dyn Lifecycle>;
let ctx: Context = current_context();
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_lifecycle(node, hooks);
},
(),
);
instance.on_mount(node);
node
}
}
pub trait ComponentProps: Sized {
fn init_props() -> Self;
}