Bug 1468754 Part 8: Make ChangesActor fire events. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 30 Jul 2018 06:11:12 -0700
changeset 826144 1c062dc889b7f5cfad6bc54ed0c4736d7714aae9
parent 826143 2b9a4d173344e12f542ecc209b162085b2fb1d34
child 826145 85fe679b86557900d90a215787d5e3e3d024adb0
push id118245
push userbwerth@mozilla.com
push dateFri, 03 Aug 2018 00:03:09 +0000
bugs1468754
milestone63.0a1
Bug 1468754 Part 8: Make ChangesActor fire events. MozReview-Commit-ID: HeJbt126zoA
devtools/server/actors/changes.js
--- a/devtools/server/actors/changes.js
+++ b/devtools/server/actors/changes.js
@@ -1,15 +1,16 @@
 /* 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 protocol = require("devtools/shared/protocol");
+const EventEmitter = require("devtools/shared/event-emitter");
 const { changesSpec } = require("devtools/shared/specs/changes");
 
 /**
  * The ChangesActor stores a stack of changes made by devtools on
  * the document in the associated tab.
  */
 const ChangesActor = protocol.ActorClassWithSpec(changesSpec, {
   /**
@@ -17,16 +18,18 @@ const ChangesActor = protocol.ActorClass
    *
    * @param {InspectorActor} inspector
    *    The InspectorActor that owns this ChangesActor.
    */
   initialize: function(inspector) {
     protocol.Actor.prototype.initialize.call(this, null);
     this.inspector = inspector;
 
+    EventEmitter.decorate(this);
+
     this.changes = [];
   },
 
   destroy: function() {
     protocol.Actor.prototype.destroy.call(this);
     this.inspector = null;
   },
 
@@ -67,16 +70,17 @@ const ChangesActor = protocol.ActorClass
       stylesheetChange: {
         stylesheet: stylesheet,
         offset: offset,
         oldText: oldText,
         newText: newText,
       },
     };
     this.changes.push(change);
+    this.emit("add-change", change);
   },
 
   pushAttributeChange: function(node, ns, attribute, oldText, newText) {
     // Compose a human-readable description of the change.
     let description;
     if (!oldText) {
       // Adding an attribute.
       description = "(localize me) Add " + node + " attribute " + (ns ? ns + ":" : "") + attribute + " with value '" + newText + "'.";
@@ -94,20 +98,24 @@ const ChangesActor = protocol.ActorClass
         node: node,
         ns: ns,
         attribute: attribute,
         oldText: oldText,
         newText: newText,
       },
     };
     this.changes.push(change);
+    this.emit("add-change", change);
   },
 
   popChange: function() {
-    return this.changes.pop();
+    const change = this.changes.pop();
+    this.emit("remove-change", change);
+    return change;
   },
 
   clearChanges: function() {
     this.changes.length = 0;
+    this.emit("clear-changes");
   }
 });
 
 exports.ChangesActor = ChangesActor;