Rsx children scope placing

This commit is contained in:
2026-01-30 23:13:05 +01:00
parent 74e33fa4c2
commit e31c17ba41
4 changed files with 46 additions and 12 deletions
+20 -4
View File
@@ -6,15 +6,21 @@ use crate::{
View,
};
pub trait ToRsx {
fn to_rsx(&self) -> Rsx;
}
#[derive(Clone)]
pub enum RsxScope {
Static(Box<dyn Fn(&Arc<Scope>) + Send + Sync>),
Static(Arc<dyn Fn(&Arc<Scope>) + Send + Sync>),
Dynamic(
Arc<dyn Fn(&Arc<Scope>) + Send + Sync>,
Vec<Box<dyn HookDependency>>,
Vec<Arc<dyn HookDependency>>,
),
Child(Rsx),
}
#[derive(Clone)]
pub struct Rsx(Vec<RsxScope>);
impl Rsx {
@@ -23,18 +29,22 @@ impl Rsx {
}
pub fn static_scope<F: Fn(&Arc<Scope>) + Send + Sync + 'static>(&mut self, scope: F) {
self.0.push(RsxScope::Static(Box::new(scope)));
self.0.push(RsxScope::Static(Arc::new(scope)));
}
pub fn dynamic_scope<F: Fn(&Arc<Scope>) + Send + Sync + 'static>(
&mut self,
drawer: F,
dependencies: Vec<Box<dyn HookDependency>>,
dependencies: Vec<Arc<dyn HookDependency>>,
) {
self.0
.push(RsxScope::Dynamic(Arc::new(drawer), dependencies));
}
pub fn child<R: ToRsx>(&mut self, child: R) {
self.0.push(RsxScope::Child(child.to_rsx()));
}
pub fn generate_children(&self, context: &Arc<Context>) {
let executor = context.get_executor();
@@ -69,3 +79,9 @@ impl Rsx {
})
}
}
impl ToRsx for &Rsx {
fn to_rsx(&self) -> Rsx {
Rsx(self.0.clone())
}
}