Download packages/app/src/pages/session/session-ownership.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 843 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/pages/session/session-ownership.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/pages/session/session-ownership.ts
-
curl -L -o session-ownership.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/pages/session/session-ownership.ts
843 Bytes
| import { createComputed, onCleanup } from "solid-js" | |
| export function createSessionOwnership(sessionKey: () => string) { | |
| let current = sessionKey() | |
| let generation = 0 | |
| const transition = () => { | |
| const next = sessionKey() | |
| if (next === current) return | |
| current = next | |
| generation++ | |
| } | |
| createComputed(transition) | |
| onCleanup(() => generation++) | |
| return { | |
| key: () => { | |
| transition() | |
| return `${generation}:${current}` | |
| }, | |
| capture() { | |
| transition() | |
| const captured = generation | |
| return { | |
| key: `${captured}:${current}`, | |
| current: () => { | |
| transition() | |
| return generation === captured | |
| }, | |
| run<T>(action: () => T) { | |
| transition() | |
| if (generation !== captured) return | |
| return action() | |
| }, | |
| } | |
| }, | |
| } | |
| } | |