Updated the run macro #30 #31

This commit is contained in:
2025-08-14 15:40:39 +02:00
parent 6100023a2a
commit f51182b2b1
2 changed files with 18 additions and 15 deletions
+4 -4
View File
@@ -10,12 +10,12 @@ fn main() -> std::io::Result<()> {
pub fn app() -> Rsx {
let items: State<Vec<i32>> = use_state(vec![1, 2]);
let count = use_state(3);
run! {
use items
{
std::thread::sleep(std::time::Duration::from_millis(300));
items.get().push(3);
use count ref items {
items.get().push(count.get_dl());
**count.get() += 1;
}
}
+14 -11
View File
@@ -206,32 +206,35 @@ macro_rules! transform {
/// ```
#[macro_export]
macro_rules! run {
($(ref $r:ident)* $(use $d:ident)* $code:block) => {
(use $($d:ident),+ $(ref $($r:ident),+)? $code:block) => {
std::thread::spawn({
$(let $r = $r.clone();)* $(
let $d = $d.clone();
$d.add();
)*
$(let $d = $d.clone();)+
$($(let $r = $r.clone();)+)?
move || {
$($d.add();)+
$code
loop {
$(
if $d.check() {
$code
}
)*
if $d.check() $code
)+
std::thread::sleep(std::time::Duration::from_millis(50));
}
}
});
};
($(ref $r:ident)* $code:block) => {
(ref $($r:ident),+ $code:block) => {
std::thread::spawn({
$(let $r = $r.clone();)* $(let $d = $d.clone();)*
$(let $r = $r.clone();)+
move || $code
});
};
($($code:tt)*) => {
std::thread::spawn({
move || {$($code)*}
});
};
}
/// Constructs an `Rsx` tree using declarative syntax.