export const throttle = (fn, ms) => {
    let isTimeout = false;
    let stashedArgs;
    const throttledFn = (...args) => {
        if (!isTimeout) {
            fn(...args);
            isTimeout = true;
            setTimeout(() => {
                isTimeout = false;
                if (stashedArgs !== undefined) {
                    throttledFn(...stashedArgs);
                    stashedArgs = undefined;
                }
            }, ms);
        }
        else {
            stashedArgs = args;
        }
    };
    return throttledFn;
};
