@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
43 lines • 1.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDefaultPerformanceEntryDeduplicationStrategy = createDefaultPerformanceEntryDeduplicationStrategy;
const getPerformanceEntryHash_1 = require("./getPerformanceEntryHash");
function createDefaultPerformanceEntryDeduplicationStrategy() {
let processedPerformanceEntries = new WeakMap();
const processedPerformanceEntriesByHash = new Map();
return {
findDuplicate(span) {
if (!span.performanceEntry) {
return undefined;
}
const existing = processedPerformanceEntries.get(span.performanceEntry);
if (existing) {
return existing;
}
if (span.performanceEntry.entryType === 'resource') {
const hash = (0, getPerformanceEntryHash_1.getPerformanceEntryHash)(span.performanceEntry);
return processedPerformanceEntriesByHash.get(hash);
}
return undefined;
},
recordSpan(span, spanAndAnnotation) {
if (!span.performanceEntry) {
return;
}
processedPerformanceEntries.set(span.performanceEntry, spanAndAnnotation);
if (span.performanceEntry.entryType === 'resource') {
const hash = (0, getPerformanceEntryHash_1.getPerformanceEntryHash)(span.performanceEntry);
processedPerformanceEntriesByHash.set(hash, spanAndAnnotation);
}
},
reset() {
processedPerformanceEntries = new WeakMap();
processedPerformanceEntriesByHash.clear();
},
selectPreferredSpan(existingSpan, newSpan) {
// Default behavior: use the new span
return newSpan;
},
};
}
//# sourceMappingURL=defaultDeduplicationStrategy.js.map
;