Bug 1547307 - Part 5: Recalculate relative URL on add/root-edit. r=jlast
authorLogan Smyth <loganfsmyth@gmail.com>
Fri, 26 Apr 2019 17:38:17 +0000
changeset 530393 9ab44b7c5516c72610f15b08f616fa4877256659
parent 530392 fc69b2a782899b8bb1dc76b4eeb3ea6fd5514668
child 530394 60d4d3824604c43d50168c69faf55d82643d5327
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1547307
milestone68.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 1547307 - Part 5: Recalculate relative URL on add/root-edit. r=jlast Depends on D29018 Differential Revision: https://phabricator.services.mozilla.com/D29019
devtools/client/debugger/src/actions/breakpoints/tests/__snapshots__/breakpoints.spec.js.snap
devtools/client/debugger/src/actions/sources/tests/__snapshots__/prettyPrint.spec.js.snap
devtools/client/debugger/src/reducers/sources.js
--- a/devtools/client/debugger/src/actions/breakpoints/tests/__snapshots__/breakpoints.spec.js.snap
+++ b/devtools/client/debugger/src/actions/breakpoints/tests/__snapshots__/breakpoints.spec.js.snap
@@ -37,17 +37,17 @@ Array [
     "source": Object {
       "id": "a",
       "introductionType": null,
       "introductionUrl": null,
       "isBlackBoxed": false,
       "isExtension": false,
       "isPrettyPrinted": false,
       "isWasm": false,
-      "relativeUrl": "http://localhost:8000/examples/a",
+      "relativeUrl": "/examples/a",
       "sourceMapURL": null,
       "url": "http://localhost:8000/examples/a",
     },
   },
 ]
 `;
 
 exports[`breakpoints should not show a breakpoint that does not have text 1`] = `Array []`;
@@ -119,15 +119,15 @@ Array [
     "source": Object {
       "id": "a",
       "introductionType": null,
       "introductionUrl": null,
       "isBlackBoxed": false,
       "isExtension": false,
       "isPrettyPrinted": false,
       "isWasm": false,
-      "relativeUrl": "http://localhost:8000/examples/a",
+      "relativeUrl": "/examples/a",
       "sourceMapURL": null,
       "url": "http://localhost:8000/examples/a",
     },
   },
 ]
 `;
--- a/devtools/client/debugger/src/actions/sources/tests/__snapshots__/prettyPrint.spec.js.snap
+++ b/devtools/client/debugger/src/actions/sources/tests/__snapshots__/prettyPrint.spec.js.snap
@@ -4,17 +4,17 @@ exports[`sources - pretty print returns 
 Object {
   "id": "base.js/originalSource-36c718d4bde9a75edb388ff7733efe7f",
   "introductionType": undefined,
   "introductionUrl": null,
   "isBlackBoxed": false,
   "isExtension": false,
   "isPrettyPrinted": true,
   "isWasm": false,
-  "relativeUrl": "http://localhost:8000/examples/base.js:formatted",
+  "relativeUrl": "/examples/base.js:formatted",
   "url": "http://localhost:8000/examples/base.js:formatted",
 }
 `;
 
 exports[`sources - pretty print returns a pretty source for a minified file 2`] = `
 Object {
   "state": "fulfilled",
   "value": Object {
--- a/devtools/client/debugger/src/reducers/sources.js
+++ b/devtools/client/debugger/src/reducers/sources.js
@@ -81,26 +81,22 @@ export type SourcesState = {
 
   pendingSelectedLocation?: PendingSelectedLocation,
   selectedLocation: ?SourceLocation,
   projectDirectoryRoot: string,
   chromeAndExtenstionsEnabled: boolean,
   focusedItem: ?FocusItem
 };
 
-const emptySources = {
-  sources: {},
-  displayed: new Set(),
-  urls: {},
-  plainUrls: {}
-};
-
 export function initialSourcesState(): SourcesState {
   return {
-    ...emptySources,
+    sources: {},
+    displayed: new Set(),
+    urls: {},
+    plainUrls: {},
     content: {},
     actors: {},
     epoch: 1,
     selectedLocation: undefined,
     pendingSelectedLocation: prefs.pendingSelectedLocation,
     projectDirectoryRoot: prefs.projectDirectoryRoot,
     chromeAndExtenstionsEnabled: prefs.chromeAndExtenstionsEnabled,
     focusedItem: null
@@ -190,72 +186,51 @@ function update(
     case "SET_FOCUSED_SOURCE_ITEM":
       return { ...state, focusedItem: action.item };
   }
 
   return state;
 }
 
 /*
- * Update all of the sources when an event occurs.
- * e.g. workers are updated, project directory root changes
- */
-function updateAllSources(state: SourcesState, callback: any) {
-  const updatedSources = Object.values(state.sources).map(source => ({
-    ...source,
-    ...callback(source)
-  }));
-
-  return addSources({ ...state, ...emptySources }, updatedSources);
-}
-
-/*
  * Add sources to the sources store
  * - Add the source to the sources store
  * - Add the source URL to the urls map
  */
 function addSources(state: SourcesState, sources: Source[]): SourcesState {
   state = {
     ...state,
     content: { ...state.content },
     sources: { ...state.sources },
-    displayed: new Set(state.displayed),
     urls: { ...state.urls },
     plainUrls: { ...state.plainUrls }
   };
 
   for (const source of sources) {
     // 1. Add the source to the sources map
-    state.sources[source.id] = state.sources[source.id] || source;
-    state.content[source.id] = state.content[source.id] || null;
+    state.sources[source.id] = source;
+    state.content[source.id] = null;
 
     // 2. Update the source url map
     const existing = state.urls[source.url] || [];
     if (!existing.includes(source.id)) {
       state.urls[source.url] = [...existing, source.id];
     }
 
     // 3. Update the plain url map
     if (source.url) {
       const plainUrl = getPlainUrl(source.url);
       const existingPlainUrls = state.plainUrls[plainUrl] || [];
       if (!existingPlainUrls.includes(source.url)) {
         state.plainUrls[plainUrl] = [...existingPlainUrls, source.url];
       }
     }
+  }
 
-    // 4. Update the displayed actor map
-    if (
-      underRoot(source, state.projectDirectoryRoot) &&
-      (!source.isExtension ||
-        getChromeAndExtenstionsEnabled({ sources: state }))
-    ) {
-      state.displayed.add(source.id);
-    }
-  }
+  state = updateRootRelativeValues(state, sources);
 
   return state;
 }
 
 function insertSourceActors(state: SourcesState, action): SourcesState {
   const { items } = action;
   state = {
     ...state,
@@ -296,19 +271,56 @@ function removeSourceActors(state: Sourc
 }
 
 /*
  * Update sources when the project directory root changes
  */
 function updateProjectDirectoryRoot(state: SourcesState, root: string) {
   prefs.projectDirectoryRoot = root;
 
-  return updateAllSources({ ...state, projectDirectoryRoot: root }, source => ({
-    relativeUrl: getRelativeUrl(source, root)
-  }));
+  return updateRootRelativeValues({
+    ...state,
+    projectDirectoryRoot: root
+  });
+}
+
+function updateRootRelativeValues(
+  state: SourcesState,
+  sources?: Array<Source>
+) {
+  const ids = sources
+    ? sources.map(source => source.id)
+    : Object.keys(state.sources);
+
+  state = {
+    ...state,
+    sources: { ...state.sources },
+    displayed: new Set(state.displayed)
+  };
+
+  for (const id of ids) {
+    const source = state.sources[id];
+
+    state.displayed.delete(source.id);
+
+    if (
+      underRoot(source, state.projectDirectoryRoot) &&
+      (!source.isExtension ||
+        getChromeAndExtenstionsEnabled({ sources: state }))
+    ) {
+      state.displayed.add(source.id);
+    }
+
+    state.sources[id] = {
+      ...source,
+      relativeUrl: getRelativeUrl(source, state.projectDirectoryRoot)
+    };
+  }
+
+  return state;
 }
 
 /*
  * Update a source's loaded text content.
  */
 function updateLoadedState(
   state: SourcesState,
   action: LoadSourceAction