From 93ba2f4a7897bbca69a9fe900d4de88a99febc7f Mon Sep 17 00:00:00 2001 From: Leo dev Date: Wed, 28 Jan 2026 23:41:54 +0100 Subject: [PATCH] Implemented exectution to Context --- src/component.rs | 28 +++++++++++++++++----------- src/engine/console.rs | 2 +- src/engine/mod.rs | 2 +- src/frontend.rs | 4 +++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/component.rs b/src/component.rs index 5fd828e..e92590f 100644 --- a/src/component.rs +++ b/src/component.rs @@ -16,6 +16,7 @@ pub type EventHandler = Arc, &dyn Any) + Send + Sy pub struct Scope { pub children: Mutex, Option)>>, + executor: Arc, } pub struct Context { @@ -23,16 +24,20 @@ pub struct Context { event_handlers: Mutex>>, view: Mutex, pub(crate) scopes: Mutex>>, - // executor: Arc, + executor: Arc, } impl Context { - pub fn new) -> View + Send + Sync + 'static>(component: F) -> Arc { + pub fn new) -> View + Send + Sync + 'static>( + component: F, + executor: Arc, + ) -> Arc { Arc::new(Self { component: Mutex::new(Arc::new(component)), event_handlers: Mutex::new(HashMap::new()), view: Mutex::new(Arc::new(|_| {})), scopes: Mutex::new(Vec::new()), + executor, }) } @@ -124,9 +129,7 @@ impl Context { } pub fn scope(self: &Arc) -> Arc { - let scope = Arc::new(Scope { - children: Mutex::new(Vec::new()), - }); + let scope = Scope::new(self.executor.clone()); self.scopes.lock().unwrap().push(scope.clone()); scope @@ -137,9 +140,7 @@ impl Context { drawer: F, dependencies: &[&dyn HookDependency], ) -> Arc { - let scope = Arc::new(Scope { - children: Mutex::new(Vec::new()), - }); + let scope = Scope::new(self.executor.clone()); self.scopes.lock().unwrap().push(scope.clone()); drawer(&scope); @@ -170,12 +171,17 @@ impl Context { } } } + + pub fn get_executor(self: &Arc) -> Arc { + self.executor.clone() + } } impl Scope { - pub fn new() -> Arc { + pub fn new(executor: Arc) -> Arc { Arc::new(Self { children: Mutex::new(Vec::new()), + executor, }) } @@ -184,7 +190,7 @@ impl Scope { child: F, view_wrapper: Option, ) { - let ctx = Context::new(child); + let ctx = Context::new(child, self.executor.clone()); ctx.refresh(); @@ -192,7 +198,7 @@ impl Scope { } pub fn view(self: &Arc, view: View) { - let ctx = Context::new(move |_| view.clone()); + let ctx = Context::new(move |_| view.clone(), self.executor.clone()); ctx.refresh(); diff --git a/src/engine/console.rs b/src/engine/console.rs index bf79937..b8553a3 100644 --- a/src/engine/console.rs +++ b/src/engine/console.rs @@ -83,7 +83,7 @@ impl Engine for Console { &self, component: F, ) -> Arc { - let cx = Context::new(component); + let cx = Context::new(component, self.executor.clone()); cx.refresh(); for thread in self.threads.lock().unwrap().iter() { diff --git a/src/engine/mod.rs b/src/engine/mod.rs index daf5474..bd28fb3 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -37,6 +37,6 @@ pub trait Command { fn as_any(&self) -> &dyn Any; } -pub trait CommandExecutor { +pub trait CommandExecutor: Send + Sync { fn execute_command(&self, command: &Arc) -> crate::Result<()>; } diff --git a/src/frontend.rs b/src/frontend.rs index dbbb7c2..bcabbb5 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -35,10 +35,12 @@ impl Rsx { } pub fn view(&self, context: Arc) -> View { + let executor = context.get_executor(); + for scope in &self.0 { match scope { RsxScope::Static(scope_fn) => { - let scope = Scope::new(); + let scope = Scope::new(executor.clone()); (scope_fn)(&scope); context.scopes.lock().unwrap().push(scope) }