1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-07 14:35:26 +02:00

Update decorators.js

This commit is contained in:
Taly 2022-07-20 11:22:40 +03:00
parent 416db18138
commit 03822f7b54

View file

@ -3,11 +3,12 @@
*/
export class Decorators {
/**
* Throttle decorator function
*
* @param {Function} func - function to throttle
* @param {number} ms - milliseconds to throttle
*
* @param func
* @param ms
* @return {wrapper}
* @returns {wrapper}
*/
static throttle(func, ms) {
let isThrottled = false,
@ -15,18 +16,18 @@ export class Decorators {
savedThis;
function wrapper() {
if (isThrottled) { // (2)
if (isThrottled) {
savedArgs = arguments;
savedThis = this;
return;
}
func.apply(this, arguments); // (1)
func.apply(this, arguments);
isThrottled = true;
setTimeout(function() {
isThrottled = false; // (3)
isThrottled = false;
if (savedArgs) {
wrapper.apply(savedThis, savedArgs);