fix leading:true, trailing:false throttle

This commit is contained in:
Ramón Souza 2023-09-26 13:50:51 -03:00
parent 777715b2e4
commit bb6e843658

View File

@ -22,6 +22,10 @@ export function throttle(func, delay, options = {}) {
if (leadingExec && leading) {
execute();
leadingExec = false;
const nextExecDelay = elapsed < delay ? delay - elapsed : 0;
setTimeout(function () {
leadingExec = true;
}, nextExecDelay);
} else if (!timeoutId && trailing) {
timeoutId = setTimeout(function () {
execute();