1
0
forked from MTSR/mapserver
mapserver/static/js/util/debounce.js

17 lines
383 B
JavaScript
Raw Normal View History

2019-04-04 11:19:29 +03:00
2019-06-11 15:16:41 +03:00
export default function debounce(func, wait, immediate) {
2019-02-02 19:28:35 +03:00
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
2019-04-04 11:19:29 +03:00
if (callNow)
func.apply(context, args);
2019-02-02 19:28:35 +03:00
};
2019-04-04 11:19:29 +03:00
}