@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
22 lines (21 loc) • 537 B
JavaScript
// packages/core-data/src/utils/with-weak-map-cache.js
function withWeakMapCache(fn) {
const cache = /* @__PURE__ */ new WeakMap();
return (key) => {
let value;
if (cache.has(key)) {
value = cache.get(key);
} else {
value = fn(key);
if (key !== null && typeof key === "object") {
cache.set(key, value);
}
}
return value;
};
}
var with_weak_map_cache_default = withWeakMapCache;
export {
with_weak_map_cache_default as default
};
//# sourceMappingURL=with-weak-map-cache.js.map