[Autodesk] debounce with promise

A basic debounce 1 2 3 4 5 6 7 8 9 10 11 12 const _debounce = (fn, delay, immediate = false) => { let timer; return (...args) => { const callNow = immediate && !timer; clearTimeout(timer); timer = setTimeout(() => { timer = null; if (!immediate) fn(...args); }, delay); if (callNow) fn(...args); }; }; debounce with promise When debounce fires during mouse drag but the wrapped function calls an API and returns a Promise, you often want only the last call to run. Lodash’s debounce requires func to be a function: ...

August 11, 2022 · hyyfrank

[Autodesk] debounce with promise

A Basic debounce 1 2 3 4 5 6 7 8 9 10 11 12 const _debounce = (fn, delay, immediate = false) => { let timer; return (...args) => { const callNow = immediate && !timer; clearTimeout(timer); timer = setTimeout(() => { timer = null; if (!immediate) fn(...args); }, delay); if (callNow) fn(...args); }; }; debounce with promise If you trigger debounce while dragging the mouse, but the wrapped function calls an API and returns a Promise, you often want to run only the last invocation. How should debounce be written for that? ...

August 11, 2022 · hyyfrank