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 | 19x 19x 73x 61x 61x 51x 51x 19x | 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; }; } |