mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
refactor: use utils.debounce
fixes socket message spam in chat resize
This commit is contained in:
@@ -771,6 +771,26 @@
|
||||
}
|
||||
};
|
||||
},
|
||||
throttle: function (func, wait, immediate) {
|
||||
var timeout;
|
||||
return function () {
|
||||
var context = this;
|
||||
var args = arguments;
|
||||
var later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
var callNow = immediate && !timeout;
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(later, wait);
|
||||
}
|
||||
if (callNow) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return utils;
|
||||
|
||||
Reference in New Issue
Block a user