(fn, isEqual)
| 62 | * @returns {function} |
| 63 | */ |
| 64 | export function memoizeCompare (fn, isEqual) { |
| 65 | const memoize = function memoize () { |
| 66 | const args = [] |
| 67 | for (let i = 0; i < arguments.length; i++) { |
| 68 | args[i] = arguments[i] |
| 69 | } |
| 70 | |
| 71 | for (let c = 0; c < memoize.cache.length; c++) { |
| 72 | const cached = memoize.cache[c] |
| 73 | |
| 74 | if (isEqual(args, cached.args)) { |
| 75 | // TODO: move this cache entry to the top so recently used entries move up? |
| 76 | return cached.res |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | const res = fn.apply(fn, args) |
| 81 | memoize.cache.unshift({ args, res }) |
| 82 | |
| 83 | return res |
| 84 | } |
| 85 | |
| 86 | memoize.cache = [] |
| 87 | |
| 88 | return memoize |
| 89 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…