()
| 7 | import type { RecursivePartial } from "@/types/message.type"; |
| 8 | |
| 9 | export const useStatefulBuffer = <T>() => { |
| 10 | const currentRef = useRef<T | null>(null); |
| 11 | const buffer = useBuffer<T>(); |
| 12 | |
| 13 | const push = (update: RecursivePartial<T>) => { |
| 14 | currentRef.current = merge(currentRef.current ?? {}, update) as T; |
| 15 | if (currentRef.current) buffer.push(currentRef.current); |
| 16 | }; |
| 17 | |
| 18 | return { |
| 19 | push, |
| 20 | latest: buffer.latest, |
| 21 | delayed: buffer.delayed, |
| 22 | cleanup: buffer.cleanup, |
| 23 | maxDelay: buffer.maxDelay, |
| 24 | }; |
| 25 | }; |
no test coverage detected