diff --git a/src/component.rs b/src/component.rs index e92590f..90c910a 100644 --- a/src/component.rs +++ b/src/component.rs @@ -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) -> Arc { self.executor.clone() } + + pub fn execute(self: &Arc, command: T) -> crate::Result<()> { + self.executor + .execute_command(&(Arc::new(command) as Arc)) + } + + pub fn stop(self: &Arc) -> crate::Result<()> { + self.execute(crate::engine::commands::Stop) + } } impl Scope { diff --git a/src/engine/commands.rs b/src/engine/commands.rs index d93ee1d..8cda616 100644 --- a/src/engine/commands.rs +++ b/src/engine/commands.rs @@ -1 +1,9 @@ +use crate::engine::Command; + pub struct Stop; + +impl Command for Stop { + fn as_any(&self) -> &dyn std::any::Any { + self + } +} diff --git a/src/lib.rs b/src/lib.rs index b41e0bb..7923bda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ pub type View = Arc; pub type ViewWrapper = Arc; pub type Result = std::result::Result; +#[derive(Debug, Clone)] pub enum Error { PoisonError, }