Context implementation

This commit is contained in:
2026-01-28 23:50:08 +01:00
parent 93ba2f4a78
commit 0cf0eb42fc
3 changed files with 19 additions and 1 deletions
+10 -1
View File
@@ -5,7 +5,7 @@ use std::{
};
use crate::{
engine::CommandExecutor,
engine::{Command, CommandExecutor},
render::DrawContext,
state::{use_effect, HookDependency},
View, ViewWrapper,
@@ -175,6 +175,15 @@ impl Context {
pub fn get_executor(self: &Arc<Self>) -> Arc<dyn CommandExecutor> {
self.executor.clone()
}
pub fn execute<T: Command + 'static>(self: &Arc<Self>, command: T) -> crate::Result<()> {
self.executor
.execute_command(&(Arc::new(command) as Arc<dyn Command>))
}
pub fn stop(self: &Arc<Self>) -> crate::Result<()> {
self.execute(crate::engine::commands::Stop)
}
}
impl Scope {
+8
View File
@@ -1 +1,9 @@
use crate::engine::Command;
pub struct Stop;
impl Command for Stop {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
+1
View File
@@ -21,6 +21,7 @@ pub type View = Arc<dyn Fn(&mut DrawContext) + Send + Sync>;
pub type ViewWrapper = Arc<dyn Fn(&mut DrawContext, View) + Send + Sync>;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone)]
pub enum Error {
PoisonError,
}