Julian Descottes 64dfb85e35 Bug 1207997 - about:debugging use factories/dom helpers instead of createElement;r=janx
Make about:debugging code less verbose:
- use component factories to avoid having to remove calls to createElement
- use React.DOM helpers
- components only module.export their class
  (require('my-component.js').MyComponent -> require('my-component.js'))

MozReview-Commit-ID: CBWLgcPUkMf

--HG--
extra : rebase_source : 8e3184bf82ad1b59d65bf0e94cc2f4662db856bd
2016-02-21 01:58:00 +01:00

89 lines
2.3 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env browser */
"use strict";
const Services = require("Services");
const { createFactory, createClass, DOM: dom } =
require("devtools/client/shared/vendor/react");
const TabMenu = createFactory(require("./tab-menu"));
loader.lazyGetter(this, "AddonsTab",
() => createFactory(require("./addons-tab")));
loader.lazyGetter(this, "WorkersTab",
() => createFactory(require("./workers-tab")));
const Strings = Services.strings.createBundle(
"chrome://devtools/locale/aboutdebugging.properties");
const tabs = [{
id: "addons",
name: Strings.GetStringFromName("addons"),
icon: "chrome://devtools/skin/images/debugging-addons.svg",
component: AddonsTab
}, {
id: "workers",
name: Strings.GetStringFromName("workers"),
icon: "chrome://devtools/skin/images/debugging-workers.svg",
component: WorkersTab
}];
const defaultTabId = "addons";
module.exports = createClass({
displayName: "AboutDebuggingApp",
getInitialState() {
return {
selectedTabId: defaultTabId
};
},
componentDidMount() {
window.addEventListener("hashchange", this.onHashChange);
this.onHashChange();
this.props.telemetry.toolOpened("aboutdebugging");
},
componentWillUnmount() {
window.removeEventListener("hashchange", this.onHashChange);
this.props.telemetry.toolClosed("aboutdebugging");
this.props.telemetry.destroy();
},
render() {
let { client } = this.props;
let { selectedTabId } = this.state;
let selectTab = this.selectTab;
let selectedTab = tabs.find(t => t.id == selectedTabId);
return dom.div({ className: "app" },
TabMenu({ tabs, selectedTabId, selectTab }),
dom.div({ className: "main-content" },
selectedTab.component({ client }))
);
},
onHashChange() {
let tabId = window.location.hash.substr(1);
let isValid = tabs.some(t => t.id == tabId);
if (isValid) {
this.setState({ selectedTabId: tabId });
} else {
// If the current hash matches no valid category, navigate to the default
// tab.
this.selectTab(defaultTabId);
}
},
selectTab(tabId) {
window.location.hash = "#" + tabId;
}
});