mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
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:
parent
a14f6cc1d1
commit
b491554995
@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user