mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-30 07:46:27 +00:00
Replace timeOutAction() with debounce
Replace delegateRun() Revert my throttle/debounce setTimeout() to Function.prototype[throttle/debounce]
This commit is contained in:
34
dev/prototype-function.js
vendored
Normal file
34
dev/prototype-function.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Every time the function is executed,
|
||||
* it will delay the execution with the given amount of milliseconds.
|
||||
*/
|
||||
if (!Function.prototype.debounce) {
|
||||
Function.prototype.debounce = function(ms) {
|
||||
let func = this, timer;
|
||||
return function(...args) {
|
||||
timer && clearTimeout(timer);
|
||||
timer = setTimeout(()=>{
|
||||
func.apply(this, args)
|
||||
timer = 0;
|
||||
}, ms);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* No matter how many times the event is executed,
|
||||
* the function will be executed only once, after the given amount of milliseconds.
|
||||
*/
|
||||
if (!Function.prototype.throttle) {
|
||||
Function.prototype.throttle = function(ms) {
|
||||
let func = this, timer;
|
||||
return function(...args) {
|
||||
if (!timer) {
|
||||
timer = setTimeout(()=>{
|
||||
func.apply(this, args)
|
||||
timer = 0;
|
||||
}, ms);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user