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,
thisArg: any,
) {
let argsToUse = [] as TArgs;
let ticking = false;
return function(...args: TArgs) {
// Save the args for use later
argsToUse = args;
if (!ticking) {
ticking = true;
requestAnimFrame.call(window, () => {
ticking = false;
fn.apply(thisArg, args);
fn.apply(thisArg, argsToUse);
});
}
};