Skip to content

Instantly share code, notes, and snippets.

@rayrayzayzay
Created May 12, 2023 22:34
Show Gist options
  • Save rayrayzayzay/a60226293620e827357ef27af85314e1 to your computer and use it in GitHub Desktop.
Save rayrayzayzay/a60226293620e827357ef27af85314e1 to your computer and use it in GitHub Desktop.
const cache = new WeakMap<ElementCoords, Path2D>()
function getCachedPath(element) {
const fromCache = cache.get(element.coords)
if (fromCache) return fromCache;
const path = calculatePath(element.coords);
cache.set(element.coords, path);
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment