MCPcopy Index your code
hub / github.com/nukeop/nuclear / useLogStream

Function useLogStream

packages/player/src/hooks/useLogStream.ts:111–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

109};
110
111export const useLogStream = () => {
112 const [logs, setLogs] = useState<LogEntry[]>([]);
113
114 useEffect(() => {
115 const flushInterval = setInterval(() => {
116 setLogs(logBuffer.toArray());
117 }, FLUSH_INTERVAL_MS);
118
119 return () => {
120 clearInterval(flushInterval);
121 };
122 }, []);
123
124 const clearLogs = useCallback(() => {
125 logBuffer.clear();
126 }, []);
127
128 const scopes = useMemo(
129 () => [...new Set(logs.map((l) => l.source.scope).filter(Boolean))],
130 [logs],
131 );
132
133 const targets = useMemo(
134 () => [...new Set(logs.map((l) => l.target).filter(Boolean))],
135 [logs],
136 );
137
138 return {
139 logs,
140 scopes,
141 targets,
142 clearLogs,
143 };
144};

Callers 2

LogsFunction · 0.90

Calls 2

toArrayMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected