geocodeearth / autocomplete-element

A custom element for use with the Geocode Earth Autocomplete API.
https://geocode.earth
MIT License
8 stars 1 forks source link

custom debounce function #16

Closed missinglink closed 3 years ago

missinglink commented 3 years ago

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.

missinglink commented 3 years ago

Actually, we could probably use _.throttle(func, {leading:false, trailing:true}) to achieve the same thing?

orangejulius commented 3 years ago

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:

mxlje commented 3 years ago

closing in favor of #17