Skip to content

Commit

Permalink
Ensure that args are saved inside of the throttled helper (#10942)
Browse files Browse the repository at this point in the history
* Ensure that args are saved inside of the throttled helper

* Capture args in outer scope

* Simplify capture
  • Loading branch information
etimberg committed Dec 10, 2022
1 parent a14f6cc commit b491554
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/helpers/helpers.extras.ts
Expand Up @@ -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);
});
}
};
Expand Down

0 comments on commit b491554

Please sign in to comment.