diff --git a/examples/hello_world.rs b/examples/hello_world.rs index b00799d..c379a2c 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -24,6 +24,7 @@ fn main() { fn app(cx: &Arc) -> View { let count = use_state(0); + let mount = use_mount(); cx.on_event({ let count = count.clone(); @@ -32,7 +33,6 @@ fn app(cx: &Arc) -> View { if *count > 5 { *count = 0; - return; } @@ -41,16 +41,16 @@ fn app(cx: &Arc) -> View { }); rsx! { - if %count (*count.get() > 0) { + if %count, mount as _, (*count.get() > 0) { my_component (ctx, view) { let area = ctx.allocate(10, 0, 10, 10); ctx.draw_view(area, view); } } - for %count (i in 0..count.get_dl()) { - "{i}" - } + // for %count, mount as _, (i in 0..count.get_dl()) { + // "{i}" + // } } .view(cx.clone()) } diff --git a/src/macros.rs b/src/macros.rs index 3724013..a87d1b1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -15,12 +15,10 @@ macro_rules! rsx { #[macro_export] macro_rules! rsx_scope { - ($rsx:expr, for $(%$($dep:ident)+)? ($p:pat in $v:expr) {$($inner:tt)*} $($rest:tt)*) => { + ($rsx:expr, for $(%$($dep:ident $(as $dp:pat,)?),+)? ($p:pat in $v:expr) {$($inner:tt)*} $($rest:tt)*) => { { - $($(let $dep = $dep.clone();)+)? - $rsx.dynamic_scope({ - $($(let $dep = $dep.clone();)+)? + $($($crate::rsx_dep!($dep $(as $dp)?);)+)? move |scope| { for $p in $v { $crate::rsx_child!(scope, $($inner)*); @@ -32,12 +30,10 @@ macro_rules! rsx_scope { $crate::rsx_scope!($rsx, $($rest)*); }; - ($rsx:expr, if $(%$($dep:ident)+)? ($st:expr) {$($inner:tt)*} $($rest:tt)*) => { + ($rsx:expr, if $(%$($dep:ident $(as $dp:pat,)?),+)? ($st:expr) {$($inner:tt)*} $($rest:tt)*) => { { - $($(let $dep = $dep.clone();)+)? - $rsx.dynamic_scope({ - $($(let $dep = $dep.clone();)+)? + $($($crate::rsx_dep!($dep $(as $dp)?);)+)? move |scope| { if $st { if scope.children.lock().unwrap().len() == 0 { @@ -53,11 +49,11 @@ macro_rules! rsx_scope { $crate::rsx_scope!($rsx, $($rest)*); }; - ($rsx:expr, $(%$($dep:ident)+)? $text:literal $($rest:tt)*) => { + ($rsx:expr, $(%$($dep:ident $(as $dp:pat,)?),+)? $text:literal $($rest:tt)*) => { { let scope = $crate::component::Scope::new(); - $($(let $dep = $dep.clone();)+)? + $($($crate::rsx_dep!($dep $(as $dp)?);)+)? $crate::rsx_child!(scope, $text); @@ -121,3 +117,14 @@ macro_rules! rsx_child { ($rsx:expr,) => {}; } + +#[macro_export] +macro_rules! rsx_dep { + ($dep:ident as $dp:pat) => { + let $dp = $dep.clone(); + }; + + ($dep:ident) => { + let $dep = $dep.clone(); + }; +} diff --git a/src/state.rs b/src/state.rs index ab67050..d4c083b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -19,6 +19,7 @@ pub struct Inner<'a, T> { updated: bool, } +#[derive(Debug, Clone, Copy)] pub struct Mount; pub fn use_state(v: T) -> State {