File size: 476 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | export function resolveGlobalSingleton<T>(key: symbol, create: () => T): T {
const globalStore = globalThis as Record<PropertyKey, unknown>;
if (Object.prototype.hasOwnProperty.call(globalStore, key)) {
return globalStore[key] as T;
}
const created = create();
globalStore[key] = created;
return created;
}
export function resolveGlobalMap<TKey, TValue>(key: symbol): Map<TKey, TValue> {
return resolveGlobalSingleton(key, () => new Map<TKey, TValue>());
}
|