DocSpace-buildtools/packages/components/selection-area/selector-helpers.js

22 lines
350 B
JavaScript
Raw Normal View History

export const frames = (fn) => {
let frameId = -1;
let lock = false;
2023-02-06 11:31:53 +00:00
const next = () => {
if (!lock) {
lock = true;
frameId = requestAnimationFrame(() => {
fn();
lock = false;
});
}
};
2023-02-06 11:31:53 +00:00
const cancel = () => {
cancelAnimationFrame(frameId);
lock = false;
};
return { next, cancel };
};