@callstack/reassure-measure
Version:
Performance measurement library for React and React Native
23 lines • 974 B
JavaScript
import { format as prettyFormat, plugins } from 'pretty-format';
export function detectRedundantUpdates(elementTrees, initialRenderCount) {
const result = [];
for (let i = 1; i < elementTrees.length; i += 1) {
if (isJsonTreeEqual(elementTrees[i], elementTrees[i - 1])) {
// We want to return correct render index, so we need to take into account:
// - initial render count that happened before we have access to the element tree
// - the fact that the last initial render is double counted as first element tree
result.push(i + initialRenderCount - 1);
}
}
return result;
}
const formatOptionsZeroIndent = {
plugins: [plugins.ReactTestComponent],
indent: 0
};
function isJsonTreeEqual(left, right) {
const formattedLeft = prettyFormat(left, formatOptionsZeroIndent);
const formattedRight = prettyFormat(right, formatOptionsZeroIndent);
return formattedLeft === formattedRight;
}
//# sourceMappingURL=redundant-renders.js.map