Bug 1468754 Part 3: Add a TrackChangesEmitter helper object, and make ChangesActor listen to it. r=pbro
authorBrad Werth <bwerth@mozilla.com>
Mon, 22 Oct 2018 19:17:49 +0000
changeset 490804 a1bc85d3577fe8fb03747d33b624925505aaf157
parent 490803 17e7f300cc64af47f7f8eed90848378338449a32
child 490805 2919bc5cd4c61c3eacdc3b01d0fa84531af3d830
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerspbro
bugs1468754
milestone65.0a1
Bug 1468754 Part 3: Add a TrackChangesEmitter helper object, and make ChangesActor listen to it. r=pbro Depends on D9049 Differential Revision: https://phabricator.services.mozilla.com/D9050
devtools/server/actors/styles.js
devtools/server/actors/utils/moz.build
devtools/server/actors/utils/track-change-emitter.js
--- a/devtools/server/actors/styles.js
+++ b/devtools/server/actors/styles.js
@@ -4,16 +4,17 @@
 
 "use strict";
 
 const Services = require("Services");
 const protocol = require("devtools/shared/protocol");
 const {getCSSLexer} = require("devtools/shared/css/lexer");
 const {LongStringActor} = require("devtools/server/actors/string");
 const InspectorUtils = require("InspectorUtils");
+const TrackChangeEmitter = require("devtools/server/actors/utils/track-change-emitter");
 
 // This will also add the "stylesheet" actor type for protocol.js to recognize
 
 const {pageStyleSpec, styleRuleSpec, ELEMENT_STYLE} = require("devtools/shared/specs/styles");
 
 loader.lazyRequireGetter(this, "CssLogic", "devtools/server/actors/inspector/css-logic", true);
 loader.lazyRequireGetter(this, "SharedCssLogic", "devtools/shared/inspector/css-logic");
 loader.lazyRequireGetter(this, "getDefinedGeometryProperties",
@@ -1515,17 +1516,17 @@ var StyleRuleActor = protocol.ActorClass
     // Do not track non-changes. This can occur when typing a value in the Rule view
     // inline editor, then committing it by pressing the Enter key.
     if (data.add && data.remove &&
         data.add.property === data.remove.property &&
         data.add.value === data.remove.value) {
       return;
     }
 
-    this.emit("track-change", data);
+    TrackChangeEmitter.trackChange(data);
   },
 
   /**
    * Calls modifySelector2() which needs to be kept around for backwards compatibility.
    * TODO: Once Firefox 64 is no longer supported, inline that mehtod's content,
    * then remove its definition from this file and from specs/styles.js
    */
   modifySelector: function(node, value, editAuthored = false) {
--- a/devtools/server/actors/utils/moz.build
+++ b/devtools/server/actors/utils/moz.build
@@ -16,10 +16,11 @@ DevToolsModules(
     'event-loop.js',
     'function-call.js',
     'make-debugger.js',
     'map-uri-to-addon-id.js',
     'shapes-utils.js',
     'source-actor-store.js',
     'stack.js',
     'TabSources.js',
+    'track-change-emitter.js',
     'walker-search.js',
 )
new file mode 100644
--- /dev/null
+++ b/devtools/server/actors/utils/track-change-emitter.js
@@ -0,0 +1,26 @@
+/* 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 EventEmitter = require("devtools/shared/event-emitter");
+
+/**
+ * A helper class that is listened to by the ChangesActor, and can be
+ * used to send changes to the ChangesActor.
+ */
+class TrackChangeEmitter {
+  /**
+   * Initialize this object.
+   */
+  constructor() {
+    EventEmitter.decorate(this);
+  }
+
+  trackChange(change) {
+    this.emit("track-change", change);
+  }
+}
+
+module.exports = new TrackChangeEmitter();