Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Dec 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = Array.from(args) as TArgs;
etimberg marked this conversation as resolved.
Show resolved Hide resolved
if (!ticking) {
ticking = true;
requestAnimFrame.call(window, () => {
ticking = false;
fn.apply(thisArg, args);
fn.apply(thisArg, argsToUse);
});
}
};
Expand Down