Bug 1468754 Part 9: Stub in methods in client ChangesManager to respond to events from ChangesActor.
MozReview-Commit-ID: JnsMPFv0rl5
--- a/devtools/client/inspector/changes/change-manager.js
+++ b/devtools/client/inspector/changes/change-manager.js
@@ -3,31 +3,96 @@
/* 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 {
trackChange,
+ resetChanges,
} = require("./actions/changes");
class ChangeManager {
constructor(inspector) {
this.inspector = inspector;
this.store = this.inspector.store;
+
+ // This will be instantiated from init().
+ this.changesActor = null;
+
+ this.onAddChange = this.onAddChange.bind(this);
+ this.onRemoveChange = this.onRemoveChange.bind(this);
+ this.onClearChanges = this.onClearChanges.bind(this);
+ }
+
+ async init() {
+ this.changesActor = await this.inspector.getChanges();
+ this.changesActor.on("add-change", onAddChange);
+ this.changesActor.on("remove-change", onRemoveChange);
+ this.changesActor.on("clear-changes", onClearChanges);
}
- async track(change) {
- const defaults = { rule: null, add: null, remove: null };
- change = { ...defaults, ...change };
+ async onAddChange(data) {
+ // Turn data into a suitable change to send to the store.
+ if (data.stylesheetChange) {
+ const ssc = data.stylesheetChange;
+ const changes = _generateChangesForStylesheetChange(ssc.stylesheet,
+ ssc.offset,
+ sss.oldText,
+ ssc.newText);
+ for (const change of changes) {
+ this.store.dispatch(trackChange(change));
+ }
+ } else {
+ // We don't know how to handle any other kinds of changes.
+ // TODO: assert/warn/whatever
+ }
+ }
- // Ssee INITIAL_STATE.diff in reducers/changes.js for expected change object structure
- this.store.dispatch(trackChange(change));
+ async onRemoveChange(data) {
+ // Turn data into a suitable change that can be found in the store and removed.
+ if (data.stylesheetChange) {
+ // The store doesn't allow us to remove a change, so we instead reverse the
+ // change and let the store sort it out through its diff process.
+ const ssc = data.stylesheetChange;
+ const changes = _generateChangesForStylesheetChange(ssc.stylesheet,
+ ssc.offset,
+ sss.newText, // reversed!
+ ssc.oldText);
+ for (const change of changes) {
+ this.store.dispatch(trackChange(change));
+ }
+ } else {
+ // We don't know how to handle any other kinds of changes.
+ // TODO: assert/warn/whatever
+ }
+ }
+
+ async onClearChanges() {
+ this.store.dispatch(resetChanges());
}
destroy() {
+ if (this.changesActor) {
+ this.changesActor.off("add-change");
+ this.changesActor.off("remove-change");
+ this.changesActor.off("clear-changes");
+ this.changesActor = null;
+ }
+
this.inspector = null;
this.store = null;
}
+
+ /**
+ * Given a stylesheet, an offset, and the old and new text, determine all of the
+ * selectors that were affected, and characterize all the changes made to those
+ * selectors as individual changes of properties being added or removed.
+ **/
+ _generateChangesForStylesheetChange(stylesheet, offset, oldText, newText) {
+ let changes = [];
+ // TODO: actually do the work!
+ return changes;
+ }
}
module.exports = ChangeManager;
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -169,16 +169,20 @@ Inspector.prototype = {
async init() {
// Localize all the nodes containing a data-localization attribute.
localizeMarkup(this.panelDoc);
this._cssProperties = await initCssProperties(this.toolbox);
await this.target.makeRemote();
await this._getPageStyle();
+ if (this.changeManager) {
+ await this.changeManager.init();
+ }
+
// This may throw if the document is still loading and we are
// refering to a dead about:blank document
const defaultSelection = await this._getDefaultNodeForSelection()
.catch(this._handleRejectionIfNotDestroyed);
return this._deferredOpen(defaultSelection);
},