ToolboxHighlightController.js (1552B)
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 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 // @ts-check 5 6 /** 7 * @typedef {object} StateProps 8 * @property {RecordingState} recordingState 9 */ 10 11 /** 12 * @typedef {object} OwnProps 13 * @property {any} toolbox 14 */ 15 16 /** 17 * @typedef {StateProps & OwnProps} Props 18 * @typedef {import("../../@types/perf").State} StoreState 19 * @typedef {import("../../@types/perf").RecordingState} RecordingState 20 */ 21 22 "use strict"; 23 24 const { 25 PureComponent, 26 } = require("resource://devtools/client/shared/vendor/react.mjs"); 27 const { 28 connect, 29 } = require("resource://devtools/client/shared/vendor/react-redux.js"); 30 const selectors = require("resource://devtools/client/performance-new/store/selectors.js"); 31 32 /** 33 * @augments {React.PureComponent<Props>} 34 */ 35 class ToolboxHighlightController extends PureComponent { 36 /** @param {Props} prevProps */ 37 componentDidUpdate(prevProps) { 38 const { recordingState, toolbox } = this.props; 39 if (recordingState === "recording") { 40 toolbox.highlightTool("performance"); 41 } else if (prevProps.recordingState === "recording") { 42 toolbox.unhighlightTool("performance"); 43 } 44 } 45 46 render() { 47 return null; 48 } 49 } 50 51 /** 52 * @param {StoreState} state 53 * @returns {StateProps} 54 */ 55 function mapStateToProps(state) { 56 return { 57 recordingState: selectors.getRecordingState(state), 58 }; 59 } 60 61 module.exports = connect(mapStateToProps)(ToolboxHighlightController);