TreeMap.js (1995B)
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 } = require("resource://devtools/client/shared/vendor/react.mjs"); 10 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 11 const { treeMapModel } = require("resource://devtools/client/memory/models.js"); 12 const startVisualization = require("resource://devtools/client/memory/components/tree-map/start.js"); 13 14 class TreeMap extends Component { 15 static get propTypes() { 16 return { 17 treeMap: treeMapModel, 18 }; 19 } 20 21 constructor(props) { 22 super(props); 23 this.state = {}; 24 this._stopVisualization = this._stopVisualization.bind(this); 25 this._startVisualization = this._startVisualization.bind(this); 26 } 27 28 componentDidMount() { 29 const { treeMap } = this.props; 30 if (treeMap?.report) { 31 this._startVisualization(); 32 } 33 } 34 35 shouldComponentUpdate(nextProps) { 36 const oldTreeMap = this.props.treeMap; 37 const newTreeMap = nextProps.treeMap; 38 return oldTreeMap !== newTreeMap; 39 } 40 41 componentDidUpdate() { 42 this._stopVisualization(); 43 44 if (this.props.treeMap && this.props.treeMap.report) { 45 this._startVisualization(); 46 } 47 } 48 49 componentWillUnmount() { 50 if (this.state.stopVisualization) { 51 this.state.stopVisualization(); 52 } 53 } 54 55 _stopVisualization() { 56 if (this.state.stopVisualization) { 57 this.state.stopVisualization(); 58 this.setState({ stopVisualization: null }); 59 } 60 } 61 62 _startVisualization() { 63 const { container } = this.refs; 64 const { report } = this.props.treeMap; 65 const stopVisualization = startVisualization(container, report); 66 this.setState({ stopVisualization }); 67 } 68 69 render() { 70 return dom.div({ 71 ref: "container", 72 className: "tree-map-container", 73 }); 74 } 75 } 76 77 module.exports = TreeMap;