ZhenPort: Fixed a bug
This commit is contained in:
parent
8ed6d26c40
commit
e75b6358ef
3 changed files with 132 additions and 105 deletions
21
src/routes/zhen/Utils/Throttle.js
Normal file
21
src/routes/zhen/Utils/Throttle.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
export function throttle(callback, wait) {
|
||||
let timeoutId = null;
|
||||
let lastExecutedTime = 0;
|
||||
|
||||
return function (...args) {
|
||||
const currentTime = Date.now();
|
||||
|
||||
const execute = () => {
|
||||
lastExecutedTime = currentTime;
|
||||
callback.apply(this, args);
|
||||
};
|
||||
|
||||
if (currentTime - lastExecutedTime >= wait) {
|
||||
execute();
|
||||
} else {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(execute, wait - (currentTime - lastExecutedTime));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue