Use
requestAnimationFrame
as an async iterable, in any JavaScript environment
This package ponyfills requestAnimationFrame
internally when not available, so it works in any JavaScript environment.
npm install request-animation-frames
import requestAnimationFrames from 'request-animation-frames';
for await (const timestamp of requestAnimationFrames()) {
console.log('Animation frame timestamp:', timestamp);
drawVisualization();
}
Returns an AsyncIterable
that yields animation frame timestamps.
The first timestamp is yielded right away for easier setup.
Simply return
or break
in the loop body.
import requestAnimationFrames from 'request-animation-frames';
let shouldStop = false;
(async () => {
for await (const timestamp of requestAnimationFrames()) {
if (shouldStop) {
break;
}
console.log('Animation frame timestamp:', timestamp);
}
})();
setTimeout(() => {
shouldStop = true;
}, 10000);
- dom-mutations - Observe changes to the DOM using an async iterable