Bug 1361429 - Convert FilterButton to functional component;r=nchevobbe draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 03 May 2017 07:31:35 -0700
changeset 571932 ead2ffd56d3cf146481b0215b547b1e4abb167ed
parent 571931 eb7312eafbc15865f08dc786f8728c835df3bea0
child 626920 715db54ae414f55428d0af4ae94a7db0c1cc9741
push id56962
push userbgrinstead@mozilla.com
push dateWed, 03 May 2017 14:31:43 +0000
reviewersnchevobbe
bugs1361429
milestone55.0a1
Bug 1361429 - Convert FilterButton to functional component;r=nchevobbe MozReview-Commit-ID: 5ILDOVR3GS7
devtools/client/webconsole/new-console-output/components/filter-bar.js
devtools/client/webconsole/new-console-output/components/filter-button.js
--- a/devtools/client/webconsole/new-console-output/components/filter-bar.js
+++ b/devtools/client/webconsole/new-console-output/components/filter-bar.js
@@ -1,15 +1,14 @@
 /* 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/. */
 "use strict";
 
 const {
-  createFactory,
   createClass,
   DOM: dom,
   PropTypes
 } = require("devtools/client/shared/vendor/react");
 const { connect } = require("devtools/client/shared/vendor/react-redux");
 const { getAllFilters } = require("devtools/client/webconsole/new-console-output/selectors/filters");
 const { getAllUi } = require("devtools/client/webconsole/new-console-output/selectors/ui");
 const {
@@ -17,17 +16,17 @@ const {
   filtersClear,
   filterBarToggle,
   messagesClear
 } = require("devtools/client/webconsole/new-console-output/actions/index");
 const { l10n } = require("devtools/client/webconsole/new-console-output/utils/messages");
 const {
   MESSAGE_LEVEL
 } = require("../constants");
-const FilterButton = createFactory(require("devtools/client/webconsole/new-console-output/components/filter-button"));
+const FilterButton = require("devtools/client/webconsole/new-console-output/components/filter-button");
 
 const FilterBar = createClass({
 
   displayName: "FilterBar",
 
   propTypes: {
     dispatch: PropTypes.func.isRequired,
     filter: PropTypes.object.isRequired,
--- a/devtools/client/webconsole/new-console-output/components/filter-button.js
+++ b/devtools/client/webconsole/new-console-output/components/filter-button.js
@@ -1,47 +1,40 @@
 /* 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/. */
 "use strict";
 
 const {
-  createClass,
   DOM: dom,
   PropTypes
 } = require("devtools/client/shared/vendor/react");
 const actions = require("devtools/client/webconsole/new-console-output/actions/index");
 
-const FilterButton = createClass({
-
-  displayName: "FilterButton",
+FilterButton.displayName = "FilterButton";
 
-  propTypes: {
-    label: PropTypes.string.isRequired,
-    filterKey: PropTypes.string.isRequired,
-    active: PropTypes.bool.isRequired,
-    dispatch: PropTypes.func.isRequired,
-  },
-
-  onClick: function () {
-    this.props.dispatch(actions.filterToggle(this.props.filterKey));
-  },
+FilterButton.propTypes = {
+  label: PropTypes.string.isRequired,
+  filterKey: PropTypes.string.isRequired,
+  active: PropTypes.bool.isRequired,
+  dispatch: PropTypes.func.isRequired,
+};
 
-  render() {
-    const {active, label, filterKey} = this.props;
+function FilterButton(props) {
+  const {active, label, filterKey, dispatch} = props;
+  let classList = [
+    "devtools-button",
+    filterKey,
+  ];
+  if (active) {
+    classList.push("checked");
+  }
 
-    let classList = [
-      "devtools-button",
-      filterKey,
-    ];
-    if (active) {
-      classList.push("checked");
-    }
-
-    return dom.button({
-      "aria-pressed": active === true,
-      className: classList.join(" "),
-      onClick: this.onClick
-    }, label);
-  }
-});
+  return dom.button({
+    "aria-pressed": active === true,
+    className: classList.join(" "),
+    onClick: () => {
+      dispatch(actions.filterToggle(filterKey));
+    },
+  }, label);
+}
 
 module.exports = FilterButton;