MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / attachCoalescedResizeObserver

Function attachCoalescedResizeObserver

examples/annotations/main.ts:17–39  ·  view source on GitHub ↗
(container: HTMLElement, chart: ChartGPUInstance)

Source from the content-addressed store, hash-verified

15type DisposableResizeObserver = Pick<ResizeObserver, 'observe' | 'unobserve' | 'disconnect'>;
16
17const attachCoalescedResizeObserver = (container: HTMLElement, chart: ChartGPUInstance): DisposableResizeObserver => {
18 let rafId: number | null = null;
19 const ro = new ResizeObserver(() => {
20 if (rafId !== null) return;
21 rafId = requestAnimationFrame(() => {
22 rafId = null;
23 chart.resize();
24 });
25 });
26 ro.observe(container);
27
28 return {
29 observe: ro.observe.bind(ro),
30 unobserve: ro.unobserve.bind(ro),
31 disconnect: () => {
32 if (rafId !== null) {
33 cancelAnimationFrame(rafId);
34 rafId = null;
35 }
36 ro.disconnect();
37 },
38 };
39};
40
41const createModeToggle = (): {
42 readonly host: HTMLDivElement;

Callers 1

createChartFunction · 0.70

Calls 1

resizeMethod · 0.65

Tested by

no test coverage detected