One thing to watch out for when using debounce/throttle is the poor interaction with async functions. Debounced/throttled async functions can easily lead to unexpected behavior because they typically return the last result they have when the function is called, which would be a previous Promise for an async function. You can get a result that appears to violate causality, because the result of the promise returned by the debounce/throttle will (in a typical implementation) be from a prior invocation that happened before your debounce/throttle call.There are async-safe variants but the typical lodash-style implementations are not. If you want the semantics of "return a promise when the function is actually invoked and resolve it when the underlying async function resolves", you'll have to carefully vet if the implementation actually does that.
demetris|6 months ago
For example, debouncing is often recommended for handlers of the resize event, but, in most cases, it is not needed for handlers of observations coming from ResizeObserver.
I think this is the case for other modern APIs as well. I know that, for example, you don’t need debouncing for the relatively new scrollend event (it does the debouncing on its own).
yurishimo|6 months ago
unknown|6 months ago
[deleted]
cnity|6 months ago
[0]: https://rxjs.dev/api/index/function/switchMap
ffsm8|6 months ago
There are always countless edge cases that behave incorrectly - it might not be important and can be ignored, but while the general idea of debouncing sounds easy - and adding it to an rxjs observable is indeed straightforward...
Actually getting the desired behavior done via rxjs gets complicated super fast if you're required to be correct/spec compliant
joeframbach|6 months ago
ricardobeat|6 months ago
pas|6 months ago
tracker1|6 months ago
https://github.com/lodash/lodash/blob/8a26eb42adb303f4adc7ef...
tossandthrow|6 months ago
ncr100|6 months ago
ignoramous|6 months ago