leptos-use/src/signal_debounced.rs
2023-07-24 23:18:11 +01:00

62 lines
1.8 KiB
Rust

use crate::utils::signal_filtered;
use crate::{use_debounce_fn_with_options, DebounceOptions};
use leptos::*;
use paste::paste;
signal_filtered!(
/// Debounce changing of a `Signal` value.
///
/// ## Demo
///
/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/signal_debounced)
///
/// ## Usage
///
/// ```
/// # use leptos::*;
/// # use leptos_use::signal_debounced;
/// #
/// # #[component]
/// # fn Demo(cx: Scope) -> impl IntoView {
/// let (input, set_input) = create_signal(cx, "");
/// let debounced = signal_debounced(cx, input, 1000.0);
/// #
/// # view! { cx, }
/// # }
/// ```
///
/// ### Options
///
/// The usual debounce option `max_wait` is available.
///
/// ```
/// # use leptos::*;
/// # use leptos_use::{signal_debounced_with_options, DebounceOptions};
/// #
/// # #[component]
/// # fn Demo(cx: Scope) -> impl IntoView {
/// let (input, set_input) = create_signal(cx, "");
/// let debounced = signal_debounced_with_options(
/// cx,
/// input,
/// 1000.0,
/// DebounceOptions::default().max_wait(Some(500.0))
/// );
/// #
/// # view! { cx, }
/// # }
/// ```
///
/// ## Recommended Reading
///
/// - [**Debounce vs Throttle**: Definitive Visual Guide](https://redd.one/blog/debounce-vs-throttle)
/// - [Debouncing and Throttling Explained Through Examples](https://css-tricks.com/debouncing-throttling-explained-examples/)
///
/// ## Server-Side Rendering
///
/// Internally this uses `setTimeout` which is not supported on the server. So usually
/// a throttled signal on the server will simply be ignored.
debounce
/// [`signal_debounced`]
/// [`DebounceOptions`]
);