"use strict";
// https://codeburst.io/throttling-and-debouncing-in-javascript-b01cad5c8edf
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
const throttle = (system, func, limit) => {
    const { api: { window: { setTimeout, clearTimeout }, }, } = system;
    let lastFunc;
    let lastRan;
    return function (...args) {
        const context = this;
        if (!lastRan) {
            func.apply(context, args);
            lastRan = Date.now();
        }
        else {
            clearTimeout(lastFunc);
            lastFunc = setTimeout(function () {
                if (Date.now() - lastRan >= limit) {
                    func.apply(context, args);
                    lastRan = Date.now();
                }
            }, limit - (Date.now() - lastRan));
        }
    };
};
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map