/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/utils/refcount.ts
32 строки
772 B
Luke Parker
fix(app): start MCP servers only for open directories (#28937)
29 май 2026, 00:51
Не верифицирован
29 май 2026, 00:51
e16bfd7
Код
Авторство
О чём код?
import { onCleanup } from "solid-js" export function createRefCountMap<T>( create: (key: string) => T, remove?: (key: string) => void, identity: (key: string) => string = (key) => key, ) { const items = new Map<string, T>() const refCounts = new Map<string, number>() return (key: string) => { const id = identity(key) onCleanup(() => { refCounts.set(id, (refCounts.get(id) ?? 0) - 1) if (refCounts.get(id) === 0) { remove?.(id) items.delete(id) refCounts.delete(id) } }) const cached = items.get(id) if (cached) { refCounts.set(id, (refCounts.get(id) ?? 0) + 1) return cached } const item = create(key) items.set(id, item) refCounts.set(id, 1) return item } }