@helpscout/hsds-react
Version:
React component library for Help Scout's Design System
53 lines (41 loc) • 1.22 kB
JavaScript
exports.__esModule = true;
exports.default = exports.waitForSelectors = exports.wait = void 0;
/* istanbul ignore file */
var wait = function wait(time) {
if (time === void 0) {
time = 0;
}
return new Promise(function (resolve, reject) {
var waitTime = setTimeout(function () {
clearTimeout(waitTime);
resolve();
}, time);
});
};
exports.wait = wait;
var waitForSelectors = function waitForSelectors(selectors) {
return new Promise(function (resolve, reject) {
var timeout = 8;
var maxAttempts = 250;
var attemptToFindNodes = function attemptToFindNodes(attemptCount) {
if (attemptCount === void 0) {
attemptCount = 0;
}
if (attemptCount >= maxAttempts) {
return reject(new Error('waitForSelectors: Could not find selectors in time.'));
}
var nodeList = document.querySelectorAll(selectors);
if (nodeList.length) {
return resolve(nodeList);
}
setTimeout(function () {
attemptToFindNodes(attemptCount + 1);
}, timeout);
};
return attemptToFindNodes();
});
};
exports.waitForSelectors = waitForSelectors;
var _default = wait;
exports.default = _default;
;