Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 20x 20x 75x 63x 63x 53x 53x 20x | 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; }; } |