Bug 1422341 - Prepare VisibilityHandler.js for React 16 r?honza draft
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 01 Dec 2017 16:30:30 +0000
changeset 707523 ad3a5ad44c5a724eeccd615169ada0a17ec04a85
parent 707522 618be4014e8b41a5095cce0d50a2d0d10b3a3065
child 707538 369c8c6b080ba68a418f0de1b95545b30429091f
push id92139
push userbmo:mratcliffe@mozilla.com
push dateTue, 05 Dec 2017 12:17:48 +0000
reviewershonza
bugs1422341
milestone59.0a1
Bug 1422341 - Prepare VisibilityHandler.js for React 16 r?honza MozReview-Commit-ID: 9apN31q36qo
devtools/client/shared/components/VisibilityHandler.js
--- a/devtools/client/shared/components/VisibilityHandler.js
+++ b/devtools/client/shared/components/VisibilityHandler.js
@@ -8,40 +8,48 @@
  * Helper class to disable panel rendering when it is in background.
  *
  * Toolbox code hides the iframes when switching to another panel
  * and triggers `visibilitychange` events.
  *
  * See devtools/client/framework/toolbox.js:setIframeVisible().
  */
 
-const {
-  createClass,
-} = require("devtools/client/shared/vendor/react");
+const { Component } = require("devtools/client/shared/vendor/react");
+const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
+
+class VisibilityHandler extends Component {
+  static get propTypes() {
+    return {
+      children: PropTypes.element.isRequired
+    };
+  }
 
-const VisibilityHandler = createClass({
+  constructor(props) {
+    super(props);
 
-  displayName: "VisiblityHandler",
+    this.onVisibilityChange = this.onVisibilityChange.bind(this);
+  }
+
+  componentDidMount() {
+    window.addEventListener("visibilitychange", this.onVisibilityChange);
+  }
 
   shouldComponentUpdate() {
     return document.visibilityState == "visible";
-  },
+  }
+
+  componentWillUnmount() {
+    window.removeEventListener("visibilitychange", this.onVisibilityChange);
+  }
 
   onVisibilityChange() {
     if (document.visibilityState == "visible") {
       this.forceUpdate();
     }
-  },
-
-  componentDidMount() {
-    window.addEventListener("visibilitychange", this.onVisibilityChange);
-  },
-
-  componentWillUnmount() {
-    window.removeEventListener("visibilitychange", this.onVisibilityChange);
-  },
+  }
 
   render() {
     return this.props.children;
   }
-});
+}
 
 module.exports = VisibilityHandler;