RSX dependency
This commit is contained in:
@@ -24,6 +24,7 @@ fn main() {
|
||||
|
||||
fn app(cx: &Arc<Context>) -> 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<Context>) -> View {
|
||||
|
||||
if *count > 5 {
|
||||
*count = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,16 +41,16 @@ fn app(cx: &Arc<Context>) -> 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())
|
||||
}
|
||||
|
||||
+17
-10
@@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ pub struct Inner<'a, T> {
|
||||
updated: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Mount;
|
||||
|
||||
pub fn use_state<T>(v: T) -> State<T> {
|
||||
|
||||
Reference in New Issue
Block a user