Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/time/src/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::time::Duration;
/// The interface for calling a debounce.
///
/// See [`use_debounce`] for more information.
#[derive(Clone, Copy, PartialEq)]
pub struct UseDebounce<Args: 'static> {
current_handle: Signal<Option<TimeoutHandle>>,
timeout: UseTimeout<Args>,
Expand All @@ -30,6 +29,18 @@ impl<Args> UseDebounce<Args> {
}
}

impl<Args> Clone for UseDebounce<Args> {
fn clone(&self) -> Self {
*self
}
}
impl<Args> Copy for UseDebounce<Args> {}
impl<Args> PartialEq for UseDebounce<Args> {
fn eq(&self, other: &Self) -> bool {
self.current_handle == other.current_handle && self.timeout == other.timeout
}
}

/// A hook for allowing a function to be called only after a provided [`Duration`] has passed.
///
/// Once the [`UseDebounce::action`] method is called, a timer will start counting down until
Expand All @@ -48,7 +59,7 @@ impl<Args> UseDebounce<Args> {
/// // Create a two second debounce.
/// // This will print "ran" after two seconds since the last action call.
/// let mut debounce = use_debounce(Duration::from_secs(2), |_| println!("ran"));
///
///
/// rsx! {
/// button {
/// onclick: move |_| {
Expand All @@ -71,7 +82,7 @@ impl<Args> UseDebounce<Args> {
/// #[component]
/// fn App() -> Element {
/// let mut debounce = use_debounce(Duration::from_secs(5), |_| println!("ran"));
///
///
/// rsx! {
/// button {
/// // Start the debounce on click.
Expand Down Expand Up @@ -102,7 +113,7 @@ impl<Args> UseDebounce<Args> {
/// tokio::time::sleep(Duration::from_secs(2)).await;
/// println!("after async");
/// });
///
///
/// rsx! {
/// button {
/// onclick: move |_| {
Expand Down
Loading