mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 10:07:35 +00:00
13 lines
384 B
TypeScript
13 lines
384 B
TypeScript
// Currently only used as a WeakMap key
|
|
export default class UserContext {}
|
|
|
|
export function ctxWeakMapMemoize<T>(factory: () => T) {
|
|
const cache: WeakMap<UserContext, T> = new WeakMap();
|
|
return function get(ctx: UserContext): T {
|
|
if (!cache.has(ctx)) {
|
|
cache.set(ctx, factory());
|
|
}
|
|
// @ts-ignore We just put the value in there
|
|
return cache.get(ctx);
|
|
};
|
|
}
|