UNPKG

@callstack/reassure-measure

Version:

Performance measurement library for React and React Native

29 lines (28 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.detectRedundantUpdates = detectRedundantUpdates; var _prettyFormat = require("pretty-format"); 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: [_prettyFormat.plugins.ReactTestComponent], indent: 0 }; function isJsonTreeEqual(left, right) { const formattedLeft = (0, _prettyFormat.format)(left, formatOptionsZeroIndent); const formattedRight = (0, _prettyFormat.format)(right, formatOptionsZeroIndent); return formattedLeft === formattedRight; } //# sourceMappingURL=redundant-renders.js.map