GHHG10/CodeServer / opencode /packages /app /src /context /layout-helpers.ts
GHHG10's picture
download
raw
962 Bytes
import type { Accessor } from "solid-js"
export function ensureSessionKey(key: string, touch: (key: string) => void, seed: (key: string) => void) {
touch(key)
seed(key)
return key
}
export function createSessionKeyReader(sessionKey: string | Accessor<string>, ensure: (key: string) => void) {
const key = typeof sessionKey === "function" ? sessionKey : () => sessionKey
return () => {
const value = key()
ensure(value)
return value
}
}
export function pruneSessionKeys(input: {
keep?: string
max: number
used: Map<string, number>
view: string[]
tabs: string[]
}) {
if (!input.keep) return []
const keys = new Set<string>([...input.view, ...input.tabs])
if (keys.size <= input.max) return []
const score = (key: string) => {
if (key === input.keep) return Number.MAX_SAFE_INTEGER
return input.used.get(key) ?? 0
}
return Array.from(keys)
.sort((a, b) => score(b) - score(a))
.slice(input.max)
}

Xet Storage Details

Size:
962 Bytes
·
Xet hash:
efd35cc9fd83a15a701d003ce218741ffec018d8a40b49e301a4cf0e7567323f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.