remove once, restore use_hook

This commit is contained in:
Evan Almloff committed 2024-01-15 09:05:46 -06:00
1 parent 36e9eb1160
commit 01726d6656
9 files changed
+19 -23

No files matched your search

+1 -1
View File
@@ -81,7 +81,7 @@ fn events_generate() {
// #[test]
// fn components_generate() {
// fn app() -> Element {
// let render_phase = once(|| 0);
// let render_phase = use_hook(|| 0);
// *render_phase += 1;
// match *render_phase {
+4 -4
View File
@@ -16,10 +16,10 @@ fn app_drops() {
#[test]
fn hooks_drop() {
fn app() -> Element {
once(|| String::from("asd"));
once(|| String::from("asd"));
once(|| String::from("asd"));
once(|| String::from("asd"));
use_hook(|| String::from("asd"));
use_hook(|| String::from("asd"));
use_hook(|| String::from("asd"));
use_hook(|| String::from("asd"));
render! { div {} }
}
+5 -5
View File
@@ -18,7 +18,7 @@ fn test_memory_leak() {
return render!({});
}
let mut name = once(|| String::from("numbers: "));
let mut name = use_hook(|| String::from("numbers: "));
name.push_str("123 ");
@@ -76,7 +76,7 @@ fn memo_works_properly() {
return None;
}
let name = once(|| String::from("asd"));
let name = use_hook(|| String::from("asd"));
render!(
div { "Hello, world! {name}" }
@@ -117,7 +117,7 @@ fn free_works_on_root_hooks() {
}
fn app(cx: AppProps) -> Element {
let name: AppProps = once(|| cx.clone());
let name: AppProps = use_hook(|| cx.clone());
render!(child_component { inner: name.inner.clone() })
}
@@ -146,14 +146,14 @@ fn supports_async() {
let colors = use_signal(|| vec!["green", "blue", "red"]);
let padding = use_signal(|| 10);
once(|| {
use_hook(|| {
spawn(async move {
sleep(Duration::from_millis(1000)).await;
colors.with_mut(|colors| colors.reverse());
})
});
once(|| {
use_hook(|| {
spawn(async move {
sleep(Duration::from_millis(10)).await;
padding.with_mut(|padding| {
+1 -1
View File
@@ -9,7 +9,7 @@ async fn it_works() {
static POLL_COUNT: AtomicUsize = AtomicUsize::new(0);
fn app() -> Element {
once(|| {
use_hook(|| {
spawn(async {
for x in 0..10 {
tokio::time::sleep(Duration::from_micros(50)).await;