Skip to content

Commit

Permalink
Simplify requestFrame and cancelFrame (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Jan 6, 2024
1 parent 4380612 commit 2557724
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
export default function requestAnimationFrames() {
const hasRaf = typeof globalThis.requestAnimationFrame === 'function';

const requestFrame = callback => hasRaf
? globalThis.requestAnimationFrame(callback)
: setTimeout(() => callback(performance.now()), 16);
const requestFrame = hasRaf
? globalThis.requestAnimationFrame
: callback => setTimeout(() => callback(performance.now()), 16);

const cancelFrame = id => {
if (hasRaf) {
globalThis.cancelAnimationFrame(id);
} else {
clearTimeout(id);
}
};
const cancelFrame = hasRaf
? globalThis.cancelAnimationFrame
: id => clearTimeout(id);

return {
async * [Symbol.asyncIterator]() {
Expand Down

0 comments on commit 2557724

Please sign in to comment.