Implemented exectution to Context
This commit is contained in:
+17
-11
@@ -16,6 +16,7 @@ pub type EventHandler = Arc<Mutex<dyn FnMut(&Arc<Context>, &dyn Any) + Send + Sy
|
||||
|
||||
pub struct Scope {
|
||||
pub children: Mutex<Vec<(Arc<Context>, Option<ViewWrapper>)>>,
|
||||
executor: Arc<dyn CommandExecutor>,
|
||||
}
|
||||
|
||||
pub struct Context {
|
||||
@@ -23,16 +24,20 @@ pub struct Context {
|
||||
event_handlers: Mutex<HashMap<TypeId, Vec<EventHandler>>>,
|
||||
view: Mutex<View>,
|
||||
pub(crate) scopes: Mutex<Vec<Arc<Scope>>>,
|
||||
// executor: Arc<dyn CommandExecutor>,
|
||||
executor: Arc<dyn CommandExecutor>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new<F: Fn(&Arc<Self>) -> View + Send + Sync + 'static>(component: F) -> Arc<Self> {
|
||||
pub fn new<F: Fn(&Arc<Self>) -> View + Send + Sync + 'static>(
|
||||
component: F,
|
||||
executor: Arc<dyn CommandExecutor>,
|
||||
) -> Arc<Self> {
|
||||
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<Self>) -> Arc<Scope> {
|
||||
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<Scope> {
|
||||
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<Self>) -> Arc<dyn CommandExecutor> {
|
||||
self.executor.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Scope {
|
||||
pub fn new() -> Arc<Self> {
|
||||
pub fn new(executor: Arc<dyn CommandExecutor>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
children: Mutex::new(Vec::new()),
|
||||
executor,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -184,7 +190,7 @@ impl Scope {
|
||||
child: F,
|
||||
view_wrapper: Option<ViewWrapper>,
|
||||
) {
|
||||
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<Self>, view: View) {
|
||||
let ctx = Context::new(move |_| view.clone());
|
||||
let ctx = Context::new(move |_| view.clone(), self.executor.clone());
|
||||
|
||||
ctx.refresh();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user