core/apps/webapp/app/utils/singleton.ts
2025-05-27 23:24:50 +05:30

7 lines
236 B
TypeScript

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