зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1751933 - [devtools] Migrate all source-actors selectors to a selector module. r=bomsy
Differential Revision: https://phabricator.services.mozilla.com/D136890
This commit is contained in:
Родитель
37e5aa3408
Коммит
5ce285893a
|
@ -6,7 +6,7 @@ import {
|
|||
getSourceActor,
|
||||
getSourceActorBreakableLines,
|
||||
getSourceActorBreakpointColumns,
|
||||
} from "../reducers/source-actors";
|
||||
} from "../selectors/source-actors";
|
||||
import { memoizeableAction } from "../utils/memoizableAction";
|
||||
import { PROMISE } from "./utils/middleware/promise";
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* 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/>. */
|
||||
|
||||
import { asSettled } from "../utils/async-value";
|
||||
import {
|
||||
createInitial,
|
||||
insertResources,
|
||||
|
@ -10,10 +9,6 @@ import {
|
|||
removeResources,
|
||||
hasResource,
|
||||
getResource,
|
||||
getMappedResource,
|
||||
makeWeakQuery,
|
||||
makeIdQuery,
|
||||
makeReduceAllQuery,
|
||||
} from "../utils/resource";
|
||||
|
||||
import { asyncActionAsValue } from "../actions/utils/middleware/promise";
|
||||
|
@ -112,94 +107,3 @@ function updateBreakableLines(state, action) {
|
|||
|
||||
return updateResources(state, [{ id: sourceId, breakableLines: value }]);
|
||||
}
|
||||
|
||||
export function resourceAsSourceActor({
|
||||
breakpointPositions,
|
||||
breakableLines,
|
||||
...sourceActor
|
||||
}) {
|
||||
return sourceActor;
|
||||
}
|
||||
|
||||
export function hasSourceActor(state, id) {
|
||||
return hasResource(state.sourceActors, id);
|
||||
}
|
||||
|
||||
export function getSourceActor(state, id) {
|
||||
return getMappedResource(state.sourceActors, id, resourceAsSourceActor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the source actors for a set of IDs. Caches based on the identity
|
||||
* of "ids" when possible.
|
||||
*/
|
||||
const querySourceActorsById = makeIdQuery(resourceAsSourceActor);
|
||||
|
||||
export function getSourceActors(state, ids) {
|
||||
return querySourceActorsById(state.sourceActors, ids);
|
||||
}
|
||||
|
||||
const querySourcesByThreadID = makeReduceAllQuery(
|
||||
resourceAsSourceActor,
|
||||
actors => {
|
||||
return actors.reduce((acc, actor) => {
|
||||
acc[actor.thread] = acc[actor.thread] || [];
|
||||
acc[actor.thread].push(actor);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
);
|
||||
export function getSourceActorsForThread(state, ids) {
|
||||
const sourcesByThread = querySourcesByThreadID(state.sourceActors);
|
||||
|
||||
let sources = [];
|
||||
for (const id of Array.isArray(ids) ? ids : [ids]) {
|
||||
sources = sources.concat(sourcesByThread[id] || []);
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
const queryThreadsBySourceObject = makeReduceAllQuery(
|
||||
actor => ({ thread: actor.thread, source: actor.source }),
|
||||
actors =>
|
||||
actors.reduce((acc, { source, thread }) => {
|
||||
let sourceThreads = acc[source];
|
||||
if (!sourceThreads) {
|
||||
sourceThreads = [];
|
||||
acc[source] = sourceThreads;
|
||||
}
|
||||
|
||||
sourceThreads.push(thread);
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
export function getAllThreadsBySource(state) {
|
||||
return queryThreadsBySourceObject(state.sourceActors);
|
||||
}
|
||||
|
||||
export function getSourceActorBreakableLines(state, id) {
|
||||
const { breakableLines } = getResource(state.sourceActors, id);
|
||||
|
||||
return asSettled(breakableLines);
|
||||
}
|
||||
|
||||
export function getSourceActorBreakpointColumns(state, id, line) {
|
||||
const { breakpointPositions } = getResource(state.sourceActors, id);
|
||||
|
||||
return asSettled(breakpointPositions.get(line) || null);
|
||||
}
|
||||
|
||||
export const getBreakableLinesForSourceActors = makeWeakQuery({
|
||||
filter: (state, ids) => ids,
|
||||
map: ({ breakableLines }) => breakableLines,
|
||||
reduce: items =>
|
||||
Array.from(
|
||||
items.reduce((acc, item) => {
|
||||
if (item && item.state === "fulfilled") {
|
||||
acc = acc.concat(item.value);
|
||||
}
|
||||
return acc;
|
||||
}, [])
|
||||
),
|
||||
});
|
||||
|
|
|
@ -6,13 +6,6 @@ export * from "../reducers/expressions";
|
|||
export * from "../reducers/tabs";
|
||||
export * from "../reducers/threads";
|
||||
|
||||
export {
|
||||
getSourceActor,
|
||||
hasSourceActor,
|
||||
getSourceActors,
|
||||
getSourceActorsForThread,
|
||||
} from "../reducers/source-actors";
|
||||
|
||||
export * from "./ast";
|
||||
export * from "./breakpoints";
|
||||
export {
|
||||
|
@ -33,6 +26,7 @@ export * from "./pending-breakpoints";
|
|||
export * from "./preview";
|
||||
export * from "./project-text-search";
|
||||
export * from "./quick-open";
|
||||
export * from "./source-actors";
|
||||
export * from "./source-tree";
|
||||
export * from "./sources";
|
||||
export * from "./tabs";
|
||||
|
|
|
@ -22,6 +22,7 @@ CompiledModules(
|
|||
"preview.js",
|
||||
"project-text-search.js",
|
||||
"quick-open.js",
|
||||
"source-actors.js",
|
||||
"source-tree.js",
|
||||
"sources.js",
|
||||
"tabs.js",
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/* 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/>. */
|
||||
|
||||
import { asSettled } from "../utils/async-value";
|
||||
import {
|
||||
hasResource,
|
||||
getResource,
|
||||
getMappedResource,
|
||||
makeWeakQuery,
|
||||
makeIdQuery,
|
||||
makeReduceAllQuery,
|
||||
} from "../utils/resource";
|
||||
|
||||
function resourceAsSourceActor({
|
||||
breakpointPositions,
|
||||
breakableLines,
|
||||
...sourceActor
|
||||
}) {
|
||||
return sourceActor;
|
||||
}
|
||||
|
||||
export function hasSourceActor(state, id) {
|
||||
return hasResource(state.sourceActors, id);
|
||||
}
|
||||
|
||||
export function getSourceActor(state, id) {
|
||||
return getMappedResource(state.sourceActors, id, resourceAsSourceActor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the source actors for a set of IDs. Caches based on the identity
|
||||
* of "ids" when possible.
|
||||
*/
|
||||
const querySourceActorsById = makeIdQuery(resourceAsSourceActor);
|
||||
|
||||
// Used by sources selectors
|
||||
export function getSourceActors(state, ids) {
|
||||
return querySourceActorsById(state.sourceActors, ids);
|
||||
}
|
||||
|
||||
const querySourcesByThreadID = makeReduceAllQuery(
|
||||
resourceAsSourceActor,
|
||||
actors => {
|
||||
return actors.reduce((acc, actor) => {
|
||||
acc[actor.thread] = acc[actor.thread] || [];
|
||||
acc[actor.thread].push(actor);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
);
|
||||
// Used by threads selectors
|
||||
export function getSourceActorsForThread(state, ids) {
|
||||
const sourcesByThread = querySourcesByThreadID(state.sourceActors);
|
||||
|
||||
let sources = [];
|
||||
for (const id of Array.isArray(ids) ? ids : [ids]) {
|
||||
sources = sources.concat(sourcesByThread[id] || []);
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
const queryThreadsBySourceObject = makeReduceAllQuery(
|
||||
actor => ({ thread: actor.thread, source: actor.source }),
|
||||
actors =>
|
||||
actors.reduce((acc, { source, thread }) => {
|
||||
let sourceThreads = acc[source];
|
||||
if (!sourceThreads) {
|
||||
sourceThreads = [];
|
||||
acc[source] = sourceThreads;
|
||||
}
|
||||
|
||||
sourceThreads.push(thread);
|
||||
return acc;
|
||||
}, {})
|
||||
);
|
||||
|
||||
// Used by threads selectors
|
||||
export function getAllThreadsBySource(state) {
|
||||
return queryThreadsBySourceObject(state.sourceActors);
|
||||
}
|
||||
|
||||
export function getSourceActorBreakableLines(state, id) {
|
||||
const { breakableLines } = getResource(state.sourceActors, id);
|
||||
|
||||
return asSettled(breakableLines);
|
||||
}
|
||||
|
||||
export function getSourceActorBreakpointColumns(state, id, line) {
|
||||
const { breakpointPositions } = getResource(state.sourceActors, id);
|
||||
|
||||
return asSettled(breakpointPositions.get(line) || null);
|
||||
}
|
||||
|
||||
// Used by sources selectors
|
||||
export const getBreakableLinesForSourceActors = makeWeakQuery({
|
||||
filter: (state, ids) => ids,
|
||||
map: ({ breakableLines }) => breakableLines,
|
||||
reduce: items =>
|
||||
Array.from(
|
||||
items.reduce((acc, item) => {
|
||||
if (item && item.state === "fulfilled") {
|
||||
acc = acc.concat(item.value);
|
||||
}
|
||||
return acc;
|
||||
}, [])
|
||||
),
|
||||
});
|
|
@ -35,7 +35,7 @@ import {
|
|||
getSourceActors,
|
||||
getAllThreadsBySource,
|
||||
getBreakableLinesForSourceActors,
|
||||
} from "../reducers/source-actors";
|
||||
} from "../selectors/source-actors";
|
||||
import { getAllThreads } from "../selectors/threads";
|
||||
|
||||
// This is used by tabs selectors
|
||||
|
|
Загрузка…
Ссылка в новой задаче