MCPcopy
hub / github.com/markmap/markmap / memoize

Function memoize

packages/markmap-common/src/util.ts:51–64  ·  view source on GitHub ↗
(fn: (...args: T) => U)

Source from the content-addressed store, hash-verified

49}
50
51export function memoize<T extends unknown[], U>(fn: (...args: T) => U) {
52 const cache: Record<string, Record<'value', U>> = {};
53 return function memoized(...args: T) {
54 const key = `${args[0]}`;
55 let data = cache[key];
56 if (!data) {
57 data = {
58 value: fn(...args),
59 };
60 cache[key] = data;
61 }
62 return data.value;
63 };
64}
65
66export function debounce<T extends unknown[], U>(
67 fn: (...args: T) => U,

Callers 1

loader.tsFile · 0.90

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected