core/apps/webapp/app/utils/singleton.ts
2025-06-07 10:19:45 +05:30

7 lines
230 B
TypeScript

export function singleton<T>(name: string, getValue: () => T): T {
const thusly = globalThis as any;
thusly.__core_singletons ??= {};
thusly.__core_singletons[name] ??= getValue();
return thusly.__core_singletons[name];
}