MCPcopy
hub / github.com/anomalyco/opencode / createSyntaxStyleMemo

Function createSyntaxStyleMemo

packages/tui/src/context/theme.tsx:306–332  ·  view source on GitHub ↗
(factory: () => SyntaxStyle)

Source from the content-addressed store, hash-verified

304})
305
306export function createSyntaxStyleMemo(factory: () => SyntaxStyle) {
307 const renderer = useRenderer()
308 const retained = new Set<SyntaxStyle>()
309 let current: SyntaxStyle | undefined
310
311 const release = (style: SyntaxStyle) => {
312 retained.add(style)
313 void renderer
314 .idle()
315 .catch(() => {})
316 .finally(() => {
317 if (!retained.delete(style)) return
318 style.destroy()
319 })
320 }
321
322 onCleanup(() => {
323 if (current) release(current)
324 })
325
326 return createMemo(() => {
327 const previous = current
328 current = factory()
329 if (previous) release(previous)
330 return current
331 })
332}

Callers 2

ReasoningPartFunction · 0.90
theme.tsxFile · 0.85

Calls 1

releaseFunction · 0.70

Tested by

no test coverage detected