Bug 1478448 - (Part 5) Add ChangeManager skeleton to pass tracked style changes to store. r=nchevobbe
authorRazvan Caliman <rcaliman@mozilla.com>
Tue, 18 Sep 2018 08:56:47 +0000
changeset 495392 a38ec78617f861200db748396c7619827089188e
parent 495391 f6942e5fdf2a68e697eab96c0660b1c4c7b702fd
child 495393 90d22ac1a1ebe65e3614740be94f0650bf8cbd61
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1478448
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1478448 - (Part 5) Add ChangeManager skeleton to pass tracked style changes to store. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D3330
devtools/client/inspector/changes/ChangesManager.js
devtools/client/inspector/changes/moz.build
devtools/client/inspector/changes/reducers/changes.js
devtools/client/inspector/inspector.js
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/changes/ChangesManager.js
@@ -0,0 +1,27 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* 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,
+} = require("./actions/changes");
+
+class ChangesManager {
+  constructor(inspector) {
+    this.store = inspector.store;
+  }
+
+  track(change) {
+    this.store.dispatch(trackChange(change));
+  }
+
+  destroy() {
+    this.store = null;
+  }
+}
+
+module.exports = ChangesManager;
--- a/devtools/client/inspector/changes/moz.build
+++ b/devtools/client/inspector/changes/moz.build
@@ -6,10 +6,11 @@
 
 DIRS += [
     'actions',
     'components',
     'reducers',
 ]
 
 DevToolsModules(
+    'ChangesManager.js',
     'ChangesView.js',
 )
--- a/devtools/client/inspector/changes/reducers/changes.js
+++ b/devtools/client/inspector/changes/reducers/changes.js
@@ -91,16 +91,26 @@ function updateDiff(diff = {}, change = 
   ref.tag = change.tag;
 
   return diff;
 }
 
 const reducers = {
 
   [TRACK_CHANGE](state, { data }) {
+    const defaults = {
+      href: "",
+      selector: "",
+      tag: null,
+      add: null,
+      remove: null
+    };
+
+    data = { ...defaults, ...data };
+
     // Update the state in-place with data about a style change (no deep clone of state).
     // TODO: redefine state as a shallow object structure after figuring how to track
     // both CSS Declarations and CSS Rules and At-Rules (@media, @keyframes, etc).
     // @See https://bugzilla.mozilla.org/show_bug.cgi?id=1491263
     return Object.assign({}, { diff: updateDiff(state.diff, data) });
   },
 
   [RESET_CHANGES](state) {
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -32,16 +32,18 @@ loader.lazyRequireGetter(this, "Highligh
 loader.lazyRequireGetter(this, "nodeConstants", "devtools/shared/dom-node-constants");
 loader.lazyRequireGetter(this, "Menu", "devtools/client/framework/menu");
 loader.lazyRequireGetter(this, "MenuItem", "devtools/client/framework/menu-item");
 loader.lazyRequireGetter(this, "ExtensionSidebar", "devtools/client/inspector/extensions/extension-sidebar");
 loader.lazyRequireGetter(this, "clipboardHelper", "devtools/shared/platform/clipboard");
 loader.lazyRequireGetter(this, "openContentLink", "devtools/client/shared/link", true);
 loader.lazyRequireGetter(this, "getScreenshotFront", "devtools/shared/fronts/screenshot", true);
 loader.lazyRequireGetter(this, "saveScreenshot", "devtools/shared/screenshot/save");
+loader.lazyRequireGetter(this, "ChangesManager",
+"devtools/client/inspector/changes/ChangesManager");
 
 loader.lazyImporter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm");
 
 const {LocalizationHelper, localizeMarkup} = require("devtools/shared/l10n");
 const INSPECTOR_L10N =
   new LocalizationHelper("devtools/client/locales/inspector.properties");
 loader.lazyGetter(this, "TOOLBOX_L10N", function() {
   return new LocalizationHelper("devtools/client/locales/toolbox.properties");
@@ -118,16 +120,19 @@ function Inspector(toolbox) {
   this.store = Store();
 
   // Map [panel id => panel instance]
   // Stores all the instances of sidebar panels like rule view, computed view, ...
   this._panels = new Map();
 
   this.reflowTracker = new ReflowTracker(this._target);
   this.styleChangeTracker = new InspectorStyleChangeTracker(this);
+  if (Services.prefs.getBoolPref(TRACK_CHANGES_ENABLED)) {
+    this.changesManager = new ChangesManager(this);
+  }
 
   // Store the URL of the target page prior to navigation in order to ensure
   // telemetry counts in the Grid Inspector are not double counted on reload.
   this.previousURL = this.target.url;
 
   this.is3PaneModeFirstRun = Services.prefs.getBoolPref(THREE_PANE_FIRST_RUN_PREF);
   this.show3PaneTooltip = Services.prefs.getBoolPref(SHOW_THREE_PANE_ONBOARDING_PREF);
 
@@ -1478,16 +1483,20 @@ Inspector.prototype = {
 
     this.teardownSplitter();
     this.teardownToolbar();
 
     this.breadcrumbs.destroy();
     this.reflowTracker.destroy();
     this.styleChangeTracker.destroy();
 
+    if (this.changesManager) {
+      this.changesManager.destroy();
+    }
+
     this._is3PaneModeChromeEnabled = null;
     this._is3PaneModeEnabled = null;
     this._notificationBox = null;
     this._target = null;
     this._toolbox = null;
     this.breadcrumbs = null;
     this.is3PaneModeFirstRun = null;
     this.panelDoc = null;