1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 9x 9x 36x 30x 30x 27x 27x 9x | const cache = new WeakMap<() => any, any>(); export function createCachedThunk<ThunkResult>( thunk: () => ThunkResult, ): () =>I ThunkResult { return () => { if (cache.has(thunk)) { return cache.get(thunk); } const result = thunk(); cache.set(thunk, result); return result; }; } |