From ec3f0933feac924eaff5a3cd31977b7ddc43a625 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Mon, 8 Apr 2024 08:05:33 -0400 Subject: [PATCH] working on examples --- examples/counter_without_macros/Cargo.toml | 2 +- examples/counter_without_macros/src/lib.rs | 2 +- examples/timer/Cargo.toml | 6 ++--- examples/timer/src/lib.rs | 27 ++++++++++++++-------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/counter_without_macros/Cargo.toml b/examples/counter_without_macros/Cargo.toml index e3367af4a..a7e4abd41 100644 --- a/examples/counter_without_macros/Cargo.toml +++ b/examples/counter_without_macros/Cargo.toml @@ -9,7 +9,7 @@ codegen-units = 1 lto = true [dependencies] -leptos = { path = "../../leptos", features = ["csr"] } +leptos = { path = "../../leptos" } console_log = "1" log = "0.4" console_error_panic_hook = "0.1.7" diff --git a/examples/counter_without_macros/src/lib.rs b/examples/counter_without_macros/src/lib.rs index 6124517f8..33f091588 100644 --- a/examples/counter_without_macros/src/lib.rs +++ b/examples/counter_without_macros/src/lib.rs @@ -1,4 +1,4 @@ -use leptos::{html::*, *}; +use leptos::{html::*, prelude::*, signals::RwSignal, IntoView}; /// A simple counter view. // A component is really just a function call: it runs once to create the DOM and reactive system diff --git a/examples/timer/Cargo.toml b/examples/timer/Cargo.toml index 77033bc26..84e7b7938 100644 --- a/examples/timer/Cargo.toml +++ b/examples/timer/Cargo.toml @@ -8,7 +8,7 @@ codegen-units = 1 lto = true [dependencies] -leptos = { path = "../../leptos", features = ["csr"] } +leptos = { path = "../../leptos" } console_log = "1" log = "0.4" console_error_panic_hook = "0.1.7" @@ -16,9 +16,7 @@ wasm-bindgen = "0.2" [dependencies.web-sys] version = "0.3" -features = [ - "Window", -] +features = ["Window"] [dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/examples/timer/src/lib.rs b/examples/timer/src/lib.rs index ada8f80fe..4e75e1d39 100644 --- a/examples/timer/src/lib.rs +++ b/examples/timer/src/lib.rs @@ -1,4 +1,10 @@ -use leptos::{leptos_dom::helpers::IntervalHandle, *}; +use leptos::{ + effect::Effect, + leptos_dom::helpers::{set_interval_with_handle, IntervalHandle}, + prelude::*, + signals::RwSignal, + *, +}; use std::time::Duration; /// Timer example, demonstrating the use of `use_interval`. @@ -6,16 +12,16 @@ use std::time::Duration; pub fn TimerDemo() -> impl IntoView { // count_a updates with a fixed interval of 1000 ms, whereas count_b has a dynamic // update interval. - let (count_a, set_count_a) = create_signal(0_i32); - let (count_b, set_count_b) = create_signal(0_i32); + let count_a = RwSignal::new(0_i32); + let count_b = RwSignal::new(0_i32); - let (interval, set_interval) = create_signal(1000); + let interval = RwSignal::new(1000); use_interval(1000, move || { - set_count_a.update(|c| *c += 1); + count_a.update(|c| *c += 1); }); use_interval(interval, move || { - set_count_b.update(|c| *c += 1); + count_b.update(|c| *c += 1); }); view! { @@ -24,9 +30,10 @@ pub fn TimerDemo() -> impl IntoView {
{count_a}
"Count B (dynamic interval, currently " {interval} " ms)"
{count_b}
- () { - set_interval.set(value); + // TODO impl Property directly on signal types in stable + () { + interval.set.set(value); } }/> @@ -41,7 +48,7 @@ where T: Into> + 'static, { let interval_millis = interval_millis.into(); - create_effect(move |prev_handle: Option| { + Effect::new(move |prev_handle: Option| { // effects get their previous return value as an argument // each time the effect runs, it will return the interval handle // so if we have a previous one, we cancel it