(id: unknown, compute: () => A)
| 40 | * @since 2.0.0 |
| 41 | */ |
| 42 | export const globalValue = <A>(id: unknown, compute: () => A): A => { |
| 43 | if (!globalStore) { |
| 44 | // @ts-expect-error |
| 45 | globalThis[globalStoreId] ??= new Map() |
| 46 | // @ts-expect-error |
| 47 | globalStore = globalThis[globalStoreId] as Map<unknown, any> |
| 48 | } |
| 49 | if (!globalStore.has(id)) { |
| 50 | globalStore.set(id, compute()) |
| 51 | } |
| 52 | return globalStore.get(id)! |
| 53 | } |
no test coverage detected
searching dependent graphs…