maz-ui
Version:
A standalone components library for Vue.Js 3 & Nuxt.Js 3
17 lines (16 loc) • 765 B
JavaScript
function checkAvailability(getRef, callback, options) {
const opts = {
maxAttempts: 20,
interval: 100,
...options
};
let attempts = 0;
function check() {
const ref = getRef();
ref != null ? opts.expectedValue !== void 0 && ref !== opts.expectedValue ? attempts < opts.maxAttempts ? (attempts++, setTimeout(check, opts.interval)) : opts.onError?.(new Error(opts.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`)) : callback(ref) : attempts < opts.maxAttempts ? (attempts++, setTimeout(check, opts.interval)) : opts.onError?.(new Error(opts.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`));
}
check();
}
export {
checkAvailability as c
};