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

use throttle instead of debounce #17

Closed missinglink closed 3 years ago

missinglink commented 3 years ago

this PR is a replacement for https://github.com/geocodeearth/autocomplete-element/pull/16 which is preferable since it's using a well tested implementation.

It replaces _.debounce with _.throttle and updates the API. This is a breaking change.

missinglink commented 3 years ago

Actually.. I think we should change the settings to { leading: true, trailing: true }.

The rationale is that connection latency will only ever affect the first 'paint' of the UI.

If the browser is sending requests every delay D and the connection has latency L, then the UI 'paints' will always follow the same pattern regardless of the connection speed:

note: I'm just showing the 'deltas' ie. the difference in time from when the previous response was received

{ leading: false, trailing: true }

D+L, D, D, D, D....
{ leading: true, trailing: true }

L, D, D, D, D....

In both of these scenarios, L only appears once, but with the second config slower connections are receiving their first request as quickly as they possibly can.