UNPKG

@shopify/theme-language-server-common

Version:

<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>

45 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.debounce = void 0; /** * debounce(fn, ms) * * A debounced function only executes once after a timer has expired. Repeated * call to the debounced function before its timer has expired result in a delayed * execution of the function. * * This is useful in cases where you have an "expensive" function that you only want * to execute after the user is idle for a little bit. * * e.g. Run theme check after the user has stopped typing for at least 100ms. * * The debounced function has the same type signature as its argument. * * The input function must return void (or else you might "bomb" when you resolve). * * @param fn a function that should be debounced * @param ms milliseconds after last function call for it to execute * @returns a function that will execute on the trailing edge of a timer with the last argument it was called with */ function debounce(fn, ms) { let timeoutId = null; let force = false; // force use a certain set of arguments in the next call const debouncedFn = (...args) => { if (timeoutId !== null && force) return; if (timeoutId !== null) clearTimeout(timeoutId); timeoutId = setTimeout(async () => { await Promise.resolve(fn(...args)); timeoutId = null; force = false; }, ms); }; debouncedFn.force = (...args) => { debouncedFn(...args); force = true; }; return debouncedFn; } exports.debounce = debounce; //# sourceMappingURL=debounce.js.map