+4
-4
@@ -10,12 +10,12 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
pub fn app() -> Rsx {
|
pub fn app() -> Rsx {
|
||||||
let items: State<Vec<i32>> = use_state(vec![1, 2]);
|
let items: State<Vec<i32>> = use_state(vec![1, 2]);
|
||||||
|
let count = use_state(3);
|
||||||
|
|
||||||
run! {
|
run! {
|
||||||
use items
|
use count ref items {
|
||||||
{
|
items.get().push(count.get_dl());
|
||||||
std::thread::sleep(std::time::Duration::from_millis(300));
|
**count.get() += 1;
|
||||||
items.get().push(3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-11
@@ -206,32 +206,35 @@ macro_rules! transform {
|
|||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! run {
|
macro_rules! run {
|
||||||
($(ref $r:ident)* $(use $d:ident)* $code:block) => {
|
(use $($d:ident),+ $(ref $($r:ident),+)? $code:block) => {
|
||||||
std::thread::spawn({
|
std::thread::spawn({
|
||||||
$(let $r = $r.clone();)* $(
|
$(let $d = $d.clone();)+
|
||||||
let $d = $d.clone();
|
$($(let $r = $r.clone();)+)?
|
||||||
$d.add();
|
|
||||||
)*
|
|
||||||
move || {
|
move || {
|
||||||
|
$($d.add();)+
|
||||||
$code
|
$code
|
||||||
loop {
|
loop {
|
||||||
$(
|
$(
|
||||||
if $d.check() {
|
if $d.check() $code
|
||||||
$code
|
)+
|
||||||
}
|
|
||||||
)*
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
($(ref $r:ident)* $code:block) => {
|
(ref $($r:ident),+ $code:block) => {
|
||||||
std::thread::spawn({
|
std::thread::spawn({
|
||||||
$(let $r = $r.clone();)* $(let $d = $d.clone();)*
|
$(let $r = $r.clone();)+
|
||||||
move || $code
|
move || $code
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
($($code:tt)*) => {
|
||||||
|
std::thread::spawn({
|
||||||
|
move || {$($code)*}
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs an `Rsx` tree using declarative syntax.
|
/// Constructs an `Rsx` tree using declarative syntax.
|
||||||
|
|||||||
Reference in New Issue
Block a user