]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Ensure that args are saved inside of the throttled helper (#10942)
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 10 Dec 2022 13:21:41 +0000 (08:21 -0500)
committerGitHub <noreply@github.com>
Sat, 10 Dec 2022 13:21:41 +0000 (08:21 -0500)
* Ensure that args are saved inside of the throttled helper

* Capture args in outer scope

* Simplify capture

src/helpers/helpers.extras.ts

index 162103f85f17bbc7168c74cc84ccc7921d8cb17a..754f6050483ed0724a3831567f421b62dfa8f246 100644 (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);
       });
     }
   };