Bug 1422341 - Prepare VisibilityHandler.js for React 16 r=Honza

MozReview-Commit-ID: 9apN31q36qo

--HG--
extra : rebase_source : 133b09ba8c995368d2e0dae91dab0504e96c0651
This commit is contained in:
Michael Ratcliffe 2017-12-01 16:30:30 +00:00
Родитель 06be3310e3
Коммит 7523cf460a
1 изменённых файлов: 24 добавлений и 16 удалений

Просмотреть файл

@ -13,35 +13,43 @@
* 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");
const VisibilityHandler = createClass({
class VisibilityHandler extends Component {
static get propTypes() {
return {
children: PropTypes.element.isRequired
};
}
displayName: "VisiblityHandler",
constructor(props) {
super(props);
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;