async-raf
Get async animation frame context
Install
npm install --save async-raf
Why?
When you want to get a value from requestAnimationFrame, instead of:
const area = await new Promise((resolve) => {
window.requestAnimationFrame(() => {
const { offsetWidth, offsetHeight } = someElement;
resolve(offsetWidth * offsetHeight);
});
});
You can use AsynRAF:
const area = await asyncRaf(() => {
const { offsetWidth, offsetHeight } = someElement;
return offsetWidth * offsetHeight;
});
Usage
asyncRaf(() => {
const { offsetWidth, offsetHeight } = someElement;
return offsetWidth * offsetHeight;
});
asyncRaf((resolve) => {
const { offsetWidth, offsetHeight } = someElement;
resolve(offsetWidth * offsetHeight);
});
asyncRaf(async () => {
const { offsetWidth, offsetHeight } = someElement;
const area = await calculateElementArea(offsetWidth, offsetHeight);
return area;
});
License
MIT