mirror of
https://github.com/videojs/video.js.git
synced 2025-07-13 01:30:17 +02:00
Refactor throttle in utils/fn.js
This commit is contained in:
@ -60,19 +60,15 @@ export const bind_ = function(context, fn, uid) {
|
|||||||
*
|
*
|
||||||
* @return {Function}
|
* @return {Function}
|
||||||
*/
|
*/
|
||||||
export const throttle = function(fn, wait) {
|
export const throttle = function(func, delay) {
|
||||||
let last = window.performance.now();
|
let lastCallTime = 0;
|
||||||
|
return function throttled(...args) {
|
||||||
const throttled = function(...args) {
|
const currentTime = Date.now()
|
||||||
const now = window.performance.now();
|
if (currentTime - lastCallTime >= delay) {
|
||||||
|
lastCallTime = currentTime;
|
||||||
if (now - last >= wait) {
|
func(...args);
|
||||||
fn(...args);
|
|
||||||
last = now;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return throttled;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user