🌳
pt0/serverF/genGlobal2CtxF.mts
1export const genGlobal2Ctx = <T,>() => {
2 // Unique key per instance — previously all instances shared one 'myVal' slot,
3 // so two contexts collided (last enterWith wins). Symbol keys isolate them.
4 const key = Symbol()
5 const globalAny = global as Record<symbol, unknown>
7 const enterWith = (newVal: T) => {
8 globalAny[key] = newVal
9 }
11 return {
12 enterWith,
13 getStore: () => globalAny[key] as T | undefined
14 }