mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
Merged via squash.
Prepared head SHA: 0b341f6f4c
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
14 lines
476 B
TypeScript
14 lines
476 B
TypeScript
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>());
|
|
}
|