UNPKG

mout

Version:

Modular Utilities

33 lines (32 loc) 791 B
"use strict"; exports.__esModule = true; /** * Debounce callback execution */ function debounce(fn, threshold, isAsap) { var timeout; var result; function debounced() { var args = arguments; var context = this; function delayed() { if (!isAsap) { result = fn.apply(context, args); } timeout = null; } if (timeout) { clearTimeout(timeout); } else if (isAsap) { result = fn.apply(context, args); } timeout = setTimeout(delayed, threshold); return result; } debounced.cancel = function () { clearTimeout(timeout); }; return debounced; } exports["default"] = debounce;