use std::sync::{Arc, Mutex}; use crate::{engine::CommandExecutor, View, ViewWrapper}; use super::{context::Context, ComponentImpl}; pub struct Scope { pub children: Mutex, Option)>>, executor: Arc, } impl Scope { pub fn new(executor: Arc) -> Arc { Arc::new(Self { children: Mutex::new(Vec::new()), executor, }) } pub fn child( self: &Arc, child: F, view_wrapper: Option, ) { let ctx = Context::new(child, self.executor.clone()); ctx.refresh(); self.children.lock().unwrap().push((ctx, view_wrapper)); } pub fn view(self: &Arc, view: View) { let ctx = Context::new(view, self.executor.clone()); ctx.refresh(); self.children.lock().unwrap().push((ctx, None)); } }