Closed missinglink closed 3 years ago
Actually, we could probably use _.throttle(func, {leading:false, trailing:true})
to achieve the same thing?
Yeah, that really is a great article.
I agree that we actually probably want _.throttle
.
I'd also add that in my opinion we want both leading: true
and`trailing:true
. Here's my thought process:
trailing: true
because the last request sent has to be for the most recent input typed. Otherwise people would get results for "india" when they kept typing and eventually entered "indiana".trailing: true
is that there's essentially an idle time at the beginning: the person has typed a bunch of characters but no request have been set to the server yet. Adding leading: true
ensures that some sort of query is sent right away. This isn't as important, but it feels like it would improve responsiveness a little.closing in favor of #17
after much discussion I've come to the conclusion that it's the lodash implementation of
_.debounce
that is causing the UI to not refresh as often as I'd like.there's a really amazing article which covers debouce and throttle and has a really cool demo.
if you wiggle the mouse over the "Trigger Area" in that demo for several seconds you'll see that the function only triggers once you stop wiggling, it doesn't execute once per $delay, which I what I'd like to see for autocomplete search.
this PR includes a custom
debounce
function, it actually turned out very lean, the idea here is that we have "invocation windows" and we schedule execution at the trailing end of each window.if another invocation occurs within the same window it replaces the previous one.