Bug 1468754 Part 8: Make ChangesActor fire events.
MozReview-Commit-ID: HeJbt126zoA
--- 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;