clojure-toolbox.com icon indicating copy to clipboard operation
clojure-toolbox.com copied to clipboard

Add debounce to search

Open SevereOverfl0w opened this issue 3 years ago • 4 comments

This makes the UI feel far less laggy while typing in a search query. It avoids applying redundant searches, which can easily add up to ~150ms per character on an older device or mobile phone.

SevereOverfl0w avatar May 14 '21 23:05 SevereOverfl0w

This seems fine in principle. Can we use rest arguments to make the debouncer more concise?

function debounce(f, wait){
  var timeout;
  return function(...args) {
    clearTimeout(timeout)
    timeout = setTimeout(f.bind(this, ...args), wait);
  }
}

Also instead of applySearch maybe filterProjectsBySearch?

var filterProjectsBySearch = debounce(function(query) {
  ...
}, 100);

weavejester avatar May 15 '21 03:05 weavejester

I've applied the rename suggestion.

The downside to using spread is that Internet Explorer support is non-existent. Is Internet Explorer support still a goal for clojure-toolbox?

SevereOverfl0w avatar May 15 '21 07:05 SevereOverfl0w

The downside to using spread is that Internet Explorer support is non-existent. Is Internet Explorer support still a goal for clojure-toolbox?

I don't believe it's ever been a goal. If someone needs IE support and raises an issue then we can revisit this, but I think it's safe to assume IE use amongst Clojure programmers is low to non-existent.

weavejester avatar May 15 '21 13:05 weavejester

As that's the case, I've pushed a shorter implementation using ES6.

SevereOverfl0w avatar May 15 '21 15:05 SevereOverfl0w