Bug 1477602 - Part 7: Move tab related logic which convert for component to middleware. r=ladybenko
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Fri, 17 Aug 2018 11:02:45 +0900
changeset 491031 dba74f5f01f0c0c1574e3cf76dab8ca8c94b1590
parent 491030 c3012c14dbf26694faf371eb9b1af9a0023e1d16
child 491032 b01461eb41f7e87ecb8751d83989a055de5d907c
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko
bugs1477602
milestone63.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 1477602 - Part 7: Move tab related logic which convert for component to middleware. r=ladybenko Differential Revision: https://phabricator.services.mozilla.com/D3758 Depends on D3757
devtools/client/aboutdebugging-new/src/create-store.js
devtools/client/aboutdebugging-new/src/middleware/debug-target-listener.js
devtools/client/aboutdebugging-new/src/middleware/moz.build
devtools/client/aboutdebugging-new/src/middleware/tab-component-data.js
devtools/client/aboutdebugging-new/src/reducers/runtime-state.js
--- a/devtools/client/aboutdebugging-new/src/create-store.js
+++ b/devtools/client/aboutdebugging-new/src/create-store.js
@@ -6,25 +6,28 @@
 
 const { applyMiddleware, createStore } = require("devtools/client/shared/vendor/redux");
 const { thunk } = require("devtools/client/shared/redux/middleware/thunk.js");
 
 const rootReducer = require("./reducers/index");
 const { RuntimeState } = require("./reducers/runtime-state");
 const { UiState } = require("./reducers/ui-state");
 const debugTargetListenerMiddleware = require("./middleware/debug-target-listener");
+const tabComponentDataMiddleware = require("./middleware/tab-component-data");
 const { getNetworkLocations } = require("./modules/network-locations");
 
 function configureStore() {
   const initialState = {
     runtime: new RuntimeState(),
     ui: getUiState()
   };
 
-  const middleware = applyMiddleware(thunk, debugTargetListenerMiddleware);
+  const middleware = applyMiddleware(thunk,
+                                     debugTargetListenerMiddleware,
+                                     tabComponentDataMiddleware);
 
   return createStore(rootReducer, initialState, middleware);
 }
 
 function getUiState() {
   const locations = getNetworkLocations();
   return new UiState(locations);
 }
--- a/devtools/client/aboutdebugging-new/src/middleware/debug-target-listener.js
+++ b/devtools/client/aboutdebugging-new/src/middleware/debug-target-listener.js
@@ -7,23 +7,23 @@
 const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
 
 const {
   CONNECT_RUNTIME_SUCCESS,
   DISCONNECT_RUNTIME_START,
 } = require("../constants");
 const Actions = require("../actions/index");
 
-function debugTargetListenerMiddleware(state) {
+function debugTargetListenerMiddleware(store) {
   const onExtensionsUpdated = () => {
-    state.dispatch(Actions.requestExtensions());
+    store.dispatch(Actions.requestExtensions());
   };
 
   const onTabsUpdated = () => {
-    state.dispatch(Actions.requestTabs());
+    store.dispatch(Actions.requestTabs());
   };
 
   const extensionsListener = {
     onDisabled() {
       onExtensionsUpdated();
     },
 
     onEnabled() {
@@ -43,34 +43,34 @@ function debugTargetListenerMiddleware(s
     },
 
     onUninstalling() {
       onExtensionsUpdated();
     },
   };
 
   const onWorkersUpdated = () => {
-    state.dispatch(Actions.requestWorkers());
+    store.dispatch(Actions.requestWorkers());
   };
 
   return next => action => {
     switch (action.type) {
       case CONNECT_RUNTIME_SUCCESS: {
         const { client } = action;
         client.addListener("tabListChanged", onTabsUpdated);
         AddonManager.addAddonListener(extensionsListener);
         client.addListener("workerListChanged", onWorkersUpdated);
         client.addListener("serviceWorkerRegistrationListChanged", onWorkersUpdated);
         client.addListener("processListChanged", onWorkersUpdated);
         client.addListener("registration-changed", onWorkersUpdated);
         client.addListener("push-subscription-modified", onWorkersUpdated);
         break;
       }
       case DISCONNECT_RUNTIME_START: {
-        const { client } = state.getState().runtime;
+        const { client } = store.getState().runtime;
         client.removeListener("tabListChanged", onTabsUpdated);
         AddonManager.removeAddonListener(extensionsListener);
         client.removeListener("workerListChanged", onWorkersUpdated);
         client.removeListener("serviceWorkerRegistrationListChanged", onWorkersUpdated);
         client.removeListener("processListChanged", onWorkersUpdated);
         client.removeListener("registration-changed", onWorkersUpdated);
         client.removeListener("push-subscription-modified", onWorkersUpdated);
         break;
--- a/devtools/client/aboutdebugging-new/src/middleware/moz.build
+++ b/devtools/client/aboutdebugging-new/src/middleware/moz.build
@@ -1,7 +1,8 @@
 # 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/.
 
 DevToolsModules(
     'debug-target-listener.js',
+    'tab-component-data.js',
 )
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/middleware/tab-component-data.js
@@ -0,0 +1,48 @@
+/* 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 {
+  DEBUG_TARGETS,
+  REQUEST_TABS_SUCCESS,
+} = require("../constants");
+
+/**
+ * This middleware converts tabs object that get from DebuggerClient.listTabs() to data
+ * which is used in DebugTargetItem.
+ */
+const tabComponentDataMiddleware = store => next => action => {
+  switch (action.type) {
+    case REQUEST_TABS_SUCCESS: {
+      action.tabs = toComponentData(action.tabs);
+      break;
+    }
+  }
+
+  return next(action);
+};
+
+function toComponentData(tabs) {
+  return tabs.map(tab => {
+    const type = DEBUG_TARGETS.TAB;
+    const id = tab.outerWindowID;
+    const icon = tab.favicon
+      ? `data:image/png;base64,${ btoa(String.fromCharCode.apply(String, tab.favicon)) }`
+      : "chrome://devtools/skin/images/globe.svg";
+    const name = tab.title || tab.url;
+    const url = tab.url;
+    return {
+      name,
+      icon,
+      id,
+      type,
+      details: {
+        url,
+      },
+    };
+  });
+}
+
+module.exports = tabComponentDataMiddleware;
--- a/devtools/client/aboutdebugging-new/src/reducers/runtime-state.js
+++ b/devtools/client/aboutdebugging-new/src/reducers/runtime-state.js
@@ -40,17 +40,17 @@ function runtimeReducer(state = RuntimeS
       const { installedExtensions, temporaryExtensions } = action;
       return Object.assign({}, state, {
         installedExtensions: toExtensionComponentData(installedExtensions),
         temporaryExtensions: toExtensionComponentData(temporaryExtensions),
       });
     }
     case REQUEST_TABS_SUCCESS: {
       const { tabs } = action;
-      return Object.assign({}, state, { tabs: toTabComponentData(tabs) });
+      return Object.assign({}, state, { tabs });
     }
     case REQUEST_WORKERS_SUCCESS: {
       const { otherWorkers, serviceWorkers, sharedWorkers } = action;
       return Object.assign({}, state, {
         otherWorkers: toWorkerComponentData(otherWorkers),
         serviceWorkers: toWorkerComponentData(serviceWorkers, true),
         sharedWorkers: toWorkerComponentData(sharedWorkers),
       });
@@ -98,37 +98,16 @@ function toExtensionComponentData(extens
         location,
         manifestURL,
         uuid,
       },
     };
   });
 }
 
-function toTabComponentData(tabs) {
-  return tabs.map(tab => {
-    const type = DEBUG_TARGETS.TAB;
-    const id = tab.outerWindowID;
-    const icon = tab.favicon
-      ? `data:image/png;base64,${ btoa(String.fromCharCode.apply(String, tab.favicon)) }`
-      : "chrome://devtools/skin/images/globe.svg";
-    const name = tab.title || tab.url;
-    const url = tab.url;
-    return {
-      name,
-      icon,
-      id,
-      type,
-      details: {
-        url,
-      },
-    };
-  });
-}
-
 function getServiceWorkerStatus(isActive, isRunning) {
   if (isActive && isRunning) {
     return SERVICE_WORKER_STATUSES.RUNNING;
   } else if (isActive) {
     return SERVICE_WORKER_STATUSES.STOPPED;
   }
   // We cannot get service worker registrations unless the registration is in
   // ACTIVE state. Unable to know the actual state ("installing", "waiting"), we