Context implementation
This commit is contained in:
+10
-1
@@ -5,7 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
engine::CommandExecutor,
|
engine::{Command, CommandExecutor},
|
||||||
render::DrawContext,
|
render::DrawContext,
|
||||||
state::{use_effect, HookDependency},
|
state::{use_effect, HookDependency},
|
||||||
View, ViewWrapper,
|
View, ViewWrapper,
|
||||||
@@ -175,6 +175,15 @@ impl Context {
|
|||||||
pub fn get_executor(self: &Arc<Self>) -> Arc<dyn CommandExecutor> {
|
pub fn get_executor(self: &Arc<Self>) -> Arc<dyn CommandExecutor> {
|
||||||
self.executor.clone()
|
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 {
|
impl Scope {
|
||||||
|
|||||||
@@ -1 +1,9 @@
|
|||||||
|
use crate::engine::Command;
|
||||||
|
|
||||||
pub struct Stop;
|
pub struct Stop;
|
||||||
|
|
||||||
|
impl Command for Stop {
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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 ViewWrapper = Arc<dyn Fn(&mut DrawContext, View) + Send + Sync>;
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
PoisonError,
|
PoisonError,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user