Created
May 12, 2023 22:34
-
-
Save rayrayzayzay/a60226293620e827357ef27af85314e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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