use std::{fmt::Debug, sync::Arc};
use async_trait::async_trait;
use r3bl_rs_utils_core::*;
use tokio::sync::RwLock;
use crate::*;
#[async_trait]
pub trait App<S, A>
where
S: Debug + Default + Clone + PartialEq + Sync + Send,
A: Debug + Default + Clone + Sync + Send,
{
async fn app_render(
&mut self,
args: GlobalScopeArgs<'_, S, A>,
) -> CommonResult<RenderPipeline>;
async fn app_handle_event(
&mut self,
args: GlobalScopeArgs<'_, S, A>,
input_event: &InputEvent,
) -> CommonResult<EventPropagation>;
fn new_owned() -> BoxedSafeApp<S, A>
where
Self: Default + Sync + Send + 'static,
{
Box::<Self>::default()
}
fn new_shared() -> SharedApp<S, A>
where
Self: Default + Sync + Send + 'static,
{
Arc::new(RwLock::new({
let mut it = Self::default();
it.init();
it
}))
}
fn init(&mut self);
fn get_component_registry(&mut self) -> &mut ComponentRegistry<S, A>;
}