diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-08 06:52:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-08 11:52:06 +0000 |
commit | d4381831209dfbbbddd6d238c68461c9601573e2 (patch) | |
tree | 87839d80f838464ff92ebc7fa652029b9329cc96 /ext/js/core/utilities.js | |
parent | 725a90dd6570044a3df6631051aaab8b026ca6c2 (diff) |
Update eslint (#638)
* Add json test
* Update vscode settings to better handle json
* Collapse eslint rules for easier readability
* Reorganize
* Update no-multi-spaces rule for JSON
* Rules updates
* Switch to @stylistic/eslint-plugin
* Update deprecated stylistic rules
* Group stylistic rules
* Simplify rules
* Move eslint env overrides to end of file
* Add test
* Move promiseAnimationFrame to separate file
* Remove unneeded eslint disable
* Remove unneeded
Diffstat (limited to 'ext/js/core/utilities.js')
-rw-r--r-- | ext/js/core/utilities.js | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/ext/js/core/utilities.js b/ext/js/core/utilities.js index 784acdaf..1b785e79 100644 --- a/ext/js/core/utilities.js +++ b/ext/js/core/utilities.js @@ -270,48 +270,3 @@ export function deferPromise() { export function promiseTimeout(delay) { return delay <= 0 ? Promise.resolve() : new Promise((resolve) => { setTimeout(resolve, delay); }); } - -/** - * Creates a promise that will resolve after the next animation frame, using `requestAnimationFrame`. - * @param {number} [timeout] A maximum duration (in milliseconds) to wait until the promise resolves. If null or omitted, no timeout is used. - * @returns {Promise<{time: number, timeout: boolean}>} A promise that is resolved with `{time, timeout}`, where `time` is the timestamp from `requestAnimationFrame`, - * and `timeout` is a boolean indicating whether the cause was a timeout or not. - * @throws The promise throws an error if animation is not supported in this context, such as in a service worker. - */ -export function promiseAnimationFrame(timeout) { - return new Promise((resolve, reject) => { - if (typeof cancelAnimationFrame !== 'function' || typeof requestAnimationFrame !== 'function') { - reject(new Error('Animation not supported in this context')); - return; - } - - /** @type {?import('core').Timeout} */ - let timer = null; - /** @type {?number} */ - let frameRequest = null; - /** - * @param {number} time - */ - const onFrame = (time) => { - frameRequest = null; - if (timer !== null) { - clearTimeout(timer); - timer = null; - } - resolve({time, timeout: false}); - }; - const onTimeout = () => { - timer = null; - if (frameRequest !== null) { - cancelAnimationFrame(frameRequest); - frameRequest = null; - } - resolve({time: performance.now(), timeout: true}); - }; - - frameRequest = requestAnimationFrame(onFrame); - if (typeof timeout === 'number') { - timer = setTimeout(onTimeout, timeout); - } - }); -} |