mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-08-01 20:34:36 +00:00
28 lines
945 B
TypeScript
28 lines
945 B
TypeScript
import { useCallback, useSyncExternalStore } from 'react';
|
|
import type { DaemonTranscriptBlock } from '@qwen-code/sdk/daemon';
|
|
import { useTranscriptStore } from '@qwen-code/webui/daemon-react-sdk';
|
|
|
|
export function useAnimationFrameTranscriptBlocks(): readonly DaemonTranscriptBlock[] {
|
|
const store = useTranscriptStore();
|
|
const subscribe = useCallback(
|
|
(notify: () => void) => {
|
|
let frame: number | null = null;
|
|
const unsubscribe = store.subscribe(() => {
|
|
if (frame !== null) return;
|
|
frame = window.requestAnimationFrame(() => {
|
|
frame = null;
|
|
notify();
|
|
});
|
|
});
|
|
return () => {
|
|
unsubscribe();
|
|
if (frame !== null) {
|
|
window.cancelAnimationFrame(frame);
|
|
}
|
|
};
|
|
},
|
|
[store],
|
|
);
|
|
const getSnapshot = useCallback(() => store.getSnapshot().blocks, [store]);
|
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
}
|