You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

15 lines
519 B

import { safeHasOwnProperty } from '../utils/globals.js';
let contextRemainingDepth = 10;
export function memo(builder) {
const previous = {};
return ((maxDepth) => {
const n = maxDepth !== undefined ? maxDepth : contextRemainingDepth;
if (!safeHasOwnProperty(previous, n)) {
const prev = contextRemainingDepth;
contextRemainingDepth = n - 1;
previous[n] = builder(n);
contextRemainingDepth = prev;
}
return previous[n];
});
}