Census.js (2638B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 Component, 9 createFactory, 10 } = require("resource://devtools/client/shared/vendor/react.mjs"); 11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 12 const Tree = createFactory( 13 require("resource://devtools/client/shared/components/VirtualizedTree.js") 14 ); 15 const CensusTreeItem = createFactory( 16 require("resource://devtools/client/memory/components/CensusTreeItem.js") 17 ); 18 const { 19 TREE_ROW_HEIGHT, 20 } = require("resource://devtools/client/memory/constants.js"); 21 const { 22 censusModel, 23 diffingModel, 24 } = require("resource://devtools/client/memory/models.js"); 25 26 class Census extends Component { 27 static get propTypes() { 28 return { 29 census: censusModel, 30 onExpand: PropTypes.func.isRequired, 31 onCollapse: PropTypes.func.isRequired, 32 onFocus: PropTypes.func.isRequired, 33 onViewSourceInDebugger: PropTypes.func.isRequired, 34 onViewIndividuals: PropTypes.func.isRequired, 35 diffing: diffingModel, 36 }; 37 } 38 39 render() { 40 const { 41 census, 42 onExpand, 43 onCollapse, 44 onFocus, 45 diffing, 46 onViewSourceInDebugger, 47 onViewIndividuals, 48 } = this.props; 49 50 const report = census.report; 51 const parentMap = census.parentMap; 52 const { totalBytes, totalCount } = report; 53 54 const getPercentBytes = 55 totalBytes === 0 ? _ => 0 : bytes => (bytes / totalBytes) * 100; 56 57 const getPercentCount = 58 totalCount === 0 ? _ => 0 : count => (count / totalCount) * 100; 59 60 return Tree({ 61 autoExpandDepth: 0, 62 preventNavigationOnArrowRight: false, 63 focused: census.focused, 64 getParent: node => { 65 const parent = parentMap[node.id]; 66 return parent === report ? null : parent; 67 }, 68 getChildren: node => node.children || [], 69 isExpanded: node => census.expanded.has(node.id), 70 onExpand, 71 onCollapse, 72 onFocus, 73 renderItem: (item, depth, focused, arrow, expanded) => 74 new CensusTreeItem({ 75 onViewSourceInDebugger, 76 item, 77 depth, 78 focused, 79 arrow, 80 expanded, 81 getPercentBytes, 82 getPercentCount, 83 diffing, 84 inverted: census.display.inverted, 85 onViewIndividuals, 86 }), 87 getRoots: () => report.children || [], 88 getKey: node => node.id, 89 itemHeight: TREE_ROW_HEIGHT, 90 }); 91 } 92 } 93 94 module.exports = Census;