(factory: () => SyntaxStyle)
| 304 | }) |
| 305 | |
| 306 | export 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 | } |
no test coverage detected