Skip to content

how to debounce? #61

@roti

Description

@roti

Hi,

I am trying to do some debouncing in quiescent, and it turns out more complicated than expected. I am aiming to have something like this:

(d/input {:value search-text :onChange #(let [newval (.. % -target -value)]
                                        (debounce (fn []
                                                    (swap! app-state assoc :search-text newval)
                                                    (do-search newval))
                                                     500))})

The effect should be that the search should happen only after the user stops typing (i.e. didn't type anything in the last 500 ms).

There are two problems here:

  1. Multiple calls of a debounced function need a shared timer value, so the above won't work. The timer value needs to be outside of the input, so it can't be constructed by debounce.
  2. But more worse is that in quiescent components are always rebuilt at rerendering, which means that the shared timer needs to be outside the component as well, which I find a weird thing to do.

Do you have a better idea how to solve this in quiescent?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions