Ensure that args are saved inside of the throttled helper (#10942)

* Ensure that args are saved inside of the throttled helper

* Capture args in outer scope

* Simplify capture
This commit is contained in:
Evert Timberg 2022-12-10 08:21:41 -05:00 committed by GitHub
parent a14f6cc1d1
commit b491554995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,14 +27,17 @@ export function throttled<TArgs extends Array<any>>(
fn: (...args: TArgs) => void, fn: (...args: TArgs) => void,
thisArg: any, thisArg: any,
) { ) {
let argsToUse = [] as TArgs;
let ticking = false; let ticking = false;
return function(...args: TArgs) { return function(...args: TArgs) {
// Save the args for use later
argsToUse = args;
if (!ticking) { if (!ticking) {
ticking = true; ticking = true;
requestAnimFrame.call(window, () => { requestAnimFrame.call(window, () => {
ticking = false; ticking = false;
fn.apply(thisArg, args); fn.apply(thisArg, argsToUse);
}); });
} }
}; };