Bug 1547811 - Part 2: Use Resource utilities to implement Source getAllDisplayedSources. r=jlast
authorLogan Smyth <loganfsmyth@gmail.com>
Mon, 29 Apr 2019 21:49:22 +0000
changeset 530801 25683968bb2f06914f19f47555c5af83e6801fb9
parent 530800 d1f430d47a6b4b4e531beb33e43239ba60c1b4f2
child 530802 b7aa4980e921826140f631725fa1ea0d604a094b
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
bugs1547811
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 1547811 - Part 2: Use Resource utilities to implement Source getAllDisplayedSources. r=jlast Depends on D29261 Differential Revision: https://phabricator.services.mozilla.com/D29262
devtools/client/debugger/src/reducers/sources.js
--- a/devtools/client/debugger/src/reducers/sources.js
+++ b/devtools/client/debugger/src/reducers/sources.js
@@ -20,19 +20,22 @@ import {
 } from "../utils/source";
 import {
   createInitial,
   insertResources,
   updateResources,
   hasResource,
   getResource,
   getResourceIds,
+  makeReduceQuery,
   makeReduceAllQuery,
+  makeMapWithArgs,
   type Resource,
   type ResourceState,
+  type ReduceQuery,
   type ReduceAllQuery
 } from "../utils/resource";
 
 import { findBreakableLines } from "../utils/breakable-lines";
 import { findPosition } from "../utils/breakpoint/breakpointPositions";
 import * as asyncValue from "../utils/async-value";
 import type { AsyncValue, SettledValue } from "../utils/async-value";
 import { originalToGeneratedId } from "devtools-source-map";
@@ -64,17 +67,16 @@ import { uniq } from "lodash";
 
 export type SourcesMap = { [SourceId]: Source };
 type SourcesContentMap = { [SourceId]: SettledValue<SourceContent> | null };
 export type BreakpointPositionsMap = { [SourceId]: BreakpointPositions };
 export type SourcesMapByThread = { [ThreadId]: SourcesMap };
 type SourceActorMap = { [SourceId]: Array<SourceActorId> };
 
 type UrlsMap = { [string]: SourceId[] };
-type DisplayedSources = Set<SourceId>;
 type PlainUrlsMap = { [string]: string[] };
 
 type SourceResource = Resource<{
   ...Source
 }>;
 export type SourceResourceState = ResourceState<SourceResource>;
 
 export type SourcesState = {
@@ -95,31 +97,26 @@ export type SourcesState = {
   // sources can have the same URL.
   urls: UrlsMap,
 
   // All full URLs belonging to a given plain (query string stripped) URL.
   // Query strings are only shown in the Sources tab if they are required for
   // disambiguation.
   plainUrls: PlainUrlsMap,
 
-  // For each thread, all sources in that thread that are under the project root
-  // and should be shown in the editor's sources pane.
-  displayed: DisplayedSources,
-
   pendingSelectedLocation?: PendingSelectedLocation,
   selectedLocation: ?SourceLocation,
   projectDirectoryRoot: string,
   chromeAndExtenstionsEnabled: boolean,
   focusedItem: ?FocusItem
 };
 
 export function initialSourcesState(): SourcesState {
   return {
     sources: createInitial(),
-    displayed: new Set(),
     urls: {},
     plainUrls: {},
     content: {},
     actors: {},
     breakpointPositions: {},
     breakableLines: {},
     epoch: 1,
     selectedLocation: undefined,
@@ -348,34 +345,23 @@ function updateRootRelativeValues(
   state: SourcesState,
   sources?: Array<Source>
 ) {
   const ids = sources
     ? sources.map(source => source.id)
     : getResourceIds(state.sources);
 
   state = {
-    ...state,
-    displayed: new Set(state.displayed)
+    ...state
   };
 
   const relativeURLUpdates = [];
   for (const id of ids) {
     const source = getResource(state.sources, id);
 
-    state.displayed.delete(source.id);
-
-    if (
-      underRoot(source, state.projectDirectoryRoot) &&
-      (!source.isExtension ||
-        getChromeAndExtenstionsEnabled({ sources: state }))
-    ) {
-      state.displayed.add(source.id);
-    }
-
     relativeURLUpdates.push({
       id,
       relativeUrl: getRelativeUrl(source, state.projectDirectoryRoot)
     });
   }
 
   state.sources = updateResources(state.sources, relativeURLUpdates);
 
@@ -787,22 +773,47 @@ export function getSelectedSourceId(stat
   const source = getSelectedSource((state: any));
   return source && source.id;
 }
 
 export function getProjectDirectoryRoot(state: OuterState): string {
   return state.sources.projectDirectoryRoot;
 }
 
-function getAllDisplayedSources(state: OuterState): DisplayedSources {
-  return state.sources.displayed;
-}
+const queryAllDisplayedSources: ReduceQuery<
+  SourceResource,
+  {| projectDirectoryRoot: string, chromeAndExtensionsEnabled: boolean |},
+  Array<SourceId>
+> = makeReduceQuery(
+  makeMapWithArgs(
+    (
+      resource,
+      ident,
+      { projectDirectoryRoot, chromeAndExtensionsEnabled }
+    ) => ({
+      id: resource.id,
+      displayed:
+        underRoot(resource, projectDirectoryRoot) &&
+        (!resource.isExtension || chromeAndExtensionsEnabled)
+    })
+  ),
+  items =>
+    items.reduce((acc, { id, displayed }) => {
+      if (displayed) {
+        acc.push(id);
+      }
+      return acc;
+    }, [])
+);
 
-function getChromeAndExtenstionsEnabled(state: OuterState) {
-  return state.sources.chromeAndExtenstionsEnabled;
+function getAllDisplayedSources(state: OuterState): Array<SourceId> {
+  return queryAllDisplayedSources(state.sources.sources, {
+    projectDirectoryRoot: state.sources.projectDirectoryRoot,
+    chromeAndExtensionsEnabled: state.sources.chromeAndExtenstionsEnabled
+  });
 }
 
 type GetDisplayedSourceIDsSelector = (
   OuterState & SourceActorOuterState
 ) => { [ThreadId]: Set<SourceId> };
 const getDisplayedSourceIDs: GetDisplayedSourceIDsSelector = createSelector(
   getThreadsBySource,
   getAllDisplayedSources,