{"version":3,"file":"createRafBatcher.mjs","sources":["../../../../admin/src/future/utils/createRafBatcher.ts"],"sourcesContent":["/**\n * Coalesces high-frequency values into at most one flush per animation frame.\n *\n * `XHR.upload.onprogress` can fire many times per second on a fast connection.\n * Dispatching each one to Redux would flood the store, so the orchestrator routes\n * progress through a batcher: many `schedule(value)` calls within a single frame\n * collapse into one `flush(latestValue)` callback.\n *\n * @param flush - Invoked once per frame with the most recent scheduled value.\n */\nexport const createRafBatcher = (flush: (value: T) => void) => {\n let frame: number | null = null;\n let latest: T;\n\n const run = () => {\n frame = null;\n flush(latest);\n };\n\n return {\n /**\n * Records the latest value and ensures a flush is scheduled for the next frame.\n * Repeated calls within the same frame overwrite the value without scheduling\n * additional frames.\n */\n schedule(value: T) {\n latest = value;\n if (frame === null) {\n frame = requestAnimationFrame(run);\n }\n },\n /**\n * Cancels any pending flush so a value scheduled this frame will not fire.\n */\n cancel() {\n if (frame !== null) {\n cancelAnimationFrame(frame);\n frame = null;\n }\n },\n };\n};\n\nexport type RafBatcher = ReturnType>;\n"],"names":["createRafBatcher","flush","frame","latest","run","schedule","value","requestAnimationFrame","cancel","cancelAnimationFrame"],"mappings":"AAAA;;;;;;;;;IAUO,MAAMA,gBAAAA,GAAmB,CAAIC,KAAAA,GAAAA;AAClC,IAAA,IAAIC,KAAAA,GAAuB,IAAA;IAC3B,IAAIC,MAAAA;AAEJ,IAAA,MAAMC,GAAAA,GAAM,IAAA;QACVF,KAAAA,GAAQ,IAAA;QACRD,KAAAA,CAAME,MAAAA,CAAAA;AACR,IAAA,CAAA;IAEA,OAAO;AACL;;;;AAIC,QACDE,UAASC,KAAQ,EAAA;YACfH,MAAAA,GAASG,KAAAA;AACT,YAAA,IAAIJ,UAAU,IAAA,EAAM;AAClBA,gBAAAA,KAAAA,GAAQK,qBAAAA,CAAsBH,GAAAA,CAAAA;AAChC,YAAA;AACF,QAAA,CAAA;AACA;;QAGAI,MAAAA,CAAAA,GAAAA;AACE,YAAA,IAAIN,UAAU,IAAA,EAAM;gBAClBO,oBAAAA,CAAqBP,KAAAA,CAAAA;gBACrBA,KAAAA,GAAQ,IAAA;AACV,YAAA;AACF,QAAA;AACF,KAAA;AACF;;;;"}