10 lines
239 B
TypeScript
10 lines
239 B
TypeScript
export const singleton = <Value>(
|
|
name: string,
|
|
valueFactory: () => Value
|
|
): Value => {
|
|
const g = global as any;
|
|
g.__singletons ??= {};
|
|
g.__singletons[name] ??= valueFactory();
|
|
return g.__singletons[name];
|
|
};
|
|
|