diff --git a/src/style.js b/src/style.js index f123ef3b6a..4fc1c9828a 100644 --- a/src/style.js +++ b/src/style.js @@ -352,21 +352,20 @@ const getFrameClip = memoizeClip((clipPath, context, dimensions) => { .attr("height", height - marginTop - marginBottom); }); -const getGeoClip = (function () { - const cache = new WeakMap(); - const sphere = {type: "Sphere"}; - return (geo, context) => { - let c, url; - if (!(c = cache.get(context))) cache.set(context, (c = new WeakMap())); - if (geo.type === "Sphere") geo = sphere; // coalesce all spheres. - if (!(url = c.get(geo))) { - const id = getClipId(); - select(context.ownerSVGElement).append("clipPath").attr("id", id).append("path").attr("d", context.path()(geo)); - c.set(geo, (url = `url(#${id})`)); - } - return url; - }; -})(); +const geoClipCache = new WeakMap(); +const sphere = {type: "Sphere"}; + +function getGeoClip(geo, context) { + let cache, url; + if (!(cache = geoClipCache.get(context))) geoClipCache.set(context, (cache = new WeakMap())); + if (geo.type === "Sphere") geo = sphere; // coalesce all spheres + if (!(url = cache.get(geo))) { + const id = getClipId(); + select(context.ownerSVGElement).append("clipPath").attr("id", id).append("path").attr("d", context.path()(geo)); + cache.set(geo, (url = `url(#${id})`)); + } + return url; +} // Note: may mutate selection.node! export function applyIndirectStyles(selection, mark, dimensions, context) {