"use strict";
// http://unscriptable.com/2009/03/20/debouncing-javascript-methods/
Object.defineProperty(exports, "__esModule", { value: true });
exports.animateDebounce = void 0;
function debounce(func, threshold = 100, execAsap = false) {
    let timeout;
    return function debounced(...args) {
        // @ts-ignore
        let obj = this;
        function delayed() {
            if (!execAsap) {
                func.apply(obj, args);
            }
            timeout = null;
        }
        if (timeout) {
            clearTimeout(timeout);
        }
        else if (execAsap) {
            func.apply(obj, args);
        }
        timeout = setTimeout(delayed, threshold);
    };
}
exports.default = debounce;
function animateDebounce(func, execAsap = false) {
    let timeout;
    return function debounced() {
        // @ts-ignore
        let obj = this;
        let args = arguments;
        function delayed() {
            if (!execAsap) {
                func.apply(obj, args);
            }
            timeout = null;
        }
        if (timeout) {
            clearTimeout(timeout);
        }
        else if (execAsap) {
            func.apply(obj, args);
        }
        timeout = requestAnimationFrame(delayed);
    };
}
exports.animateDebounce = animateDebounce;
//# sourceMappingURL=debounce.js.map