Frontend generate children
This commit is contained in:
@@ -50,5 +50,5 @@ fn BenchmarkApp(cx: &Arc<Context>, items: &usize) -> View {
|
|||||||
"Hello, world!"
|
"Hello, world!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.view(cx.clone())
|
.view(&cx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ fn App(cx: &Arc<Context>) -> View {
|
|||||||
rsx! {
|
rsx! {
|
||||||
"Hello World"
|
"Hello World"
|
||||||
}
|
}
|
||||||
.view(cx.clone())
|
.view(&cx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ fn App(cx: &Arc<Context>) -> View {
|
|||||||
rsx! {
|
rsx! {
|
||||||
"Hello, world!"
|
"Hello, world!"
|
||||||
}
|
}
|
||||||
.view(cx.clone())
|
.view(&cx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ fn App(cx: &Arc<Context>) -> View {
|
|||||||
rsx! {
|
rsx! {
|
||||||
MyComponent { "Hello world!" }
|
MyComponent { "Hello world!" }
|
||||||
}
|
}
|
||||||
.view(cx.clone())
|
.view(&cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn MyComponent(cx: &Arc<Context>, children: &Rsx) -> View {
|
fn MyComponent(cx: &Arc<Context>, children: &Rsx) -> View {
|
||||||
children.view(cx.clone())
|
children.view(&cx)
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -12,6 +12,7 @@ pub enum RsxScope {
|
|||||||
Arc<dyn Fn(&Arc<Scope>) + Send + Sync>,
|
Arc<dyn Fn(&Arc<Scope>) + Send + Sync>,
|
||||||
Vec<Box<dyn HookDependency>>,
|
Vec<Box<dyn HookDependency>>,
|
||||||
),
|
),
|
||||||
|
Child(Rsx),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Rsx(Vec<RsxScope>);
|
pub struct Rsx(Vec<RsxScope>);
|
||||||
@@ -34,7 +35,7 @@ impl Rsx {
|
|||||||
.push(RsxScope::Dynamic(Arc::new(drawer), dependencies));
|
.push(RsxScope::Dynamic(Arc::new(drawer), dependencies));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self, context: Arc<Context>) -> View {
|
pub fn generate_children(&self, context: &Arc<Context>) {
|
||||||
let executor = context.get_executor();
|
let executor = context.get_executor();
|
||||||
|
|
||||||
for scope in &self.0 {
|
for scope in &self.0 {
|
||||||
@@ -51,10 +52,16 @@ impl Rsx {
|
|||||||
&dependencies.iter().map(|d| d.as_ref()).collect::<Vec<_>>(),
|
&dependencies.iter().map(|d| d.as_ref()).collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
RsxScope::Child(child) => child.generate_children(context),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view(&self, context: &Arc<Context>) -> View {
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
|
|
||||||
|
self.generate_children(&context);
|
||||||
|
|
||||||
Arc::new({
|
Arc::new({
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
context.draw_children(ctx);
|
context.draw_children(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user