package.build.cjs.utils-hoist.memo.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Base implementation for all Sentry JavaScript SDKs
Object.defineProperty(exports, '__esModule', { value: true });
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Helper to decycle json objects
*
* @deprecated This function is deprecated and will be removed in the next major version.
*/
// TODO(v9): Move this function into normalize() directly
function memoBuilder() {
const hasWeakSet = typeof WeakSet === 'function';
const inner = hasWeakSet ? new WeakSet() : [];
function memoize(obj) {
if (hasWeakSet) {
if (inner.has(obj)) {
return true;
}
inner.add(obj);
return false;
}
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < inner.length; i++) {
const value = inner[i];
if (value === obj) {
return true;
}
}
inner.push(obj);
return false;
}
function unmemoize(obj) {
if (hasWeakSet) {
inner.delete(obj);
} else {
for (let i = 0; i < inner.length; i++) {
if (inner[i] === obj) {
inner.splice(i, 1);
break;
}
}
}
}
return [memoize, unmemoize];
}
exports.memoBuilder = memoBuilder;
//# sourceMappingURL=memo.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy