INNER CODE UNIT · TypeScript

createRafBatcher

iamlukethedev/Hermes3D · src/lib/dom/index.ts:6

export const createRafBatcher = (flush: () => void): RafBatcher => {
  let rafId: number | null = null;
  return {
    schedule: () => {
      if (rafId !== null) return;
      rafId = requestAnimationFrame(() => {
        rafId = null;
        flush();
      });
    },
    cancel: () => {
      if (rafId === null) return;
      cancelAnimationFrame(rafId);
      rafId = null;
    },
  };
};

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…