Bug 1751031 - [devtools] Migrate all thread selectors to a selector module. r=bomsy

Differential Revision: https://phabricator.services.mozilla.com/D136398
This commit is contained in:
Alexandre Poirot 2022-01-21 16:01:00 +00:00
Родитель 9aa6c53f6c
Коммит 6688d3c8fb
5 изменённых файлов: 51 добавлений и 52 удалений

Просмотреть файл

@ -51,7 +51,7 @@ import {
getAllThreadsBySource,
getBreakableLinesForSourceActors,
} from "./source-actors";
import { getAllThreads } from "./threads";
import { getAllThreads } from "../selectors/threads";
export function initialSourcesState(state) {
return {

Просмотреть файл

@ -7,8 +7,6 @@
* @module reducers/threads
*/
import { createSelector } from "reselect";
export function initialThreadsState() {
return {
threads: [],
@ -53,52 +51,3 @@ export default function update(state = initialThreadsState(), action) {
return state;
}
}
export const getWorkerCount = state => getThreads(state).length;
export function getWorkerByThread(state, thread) {
return getThreads(state).find(worker => worker.actor == thread);
}
function isMainThread(thread) {
return thread.isTopLevel;
}
export function getMainThread(state) {
return state.threads.threads.find(isMainThread);
}
export function getDebuggeeUrl(state) {
return getMainThread(state)?.url || "";
}
export const getThreads = createSelector(
state => state.threads.threads,
threads => threads.filter(thread => !isMainThread(thread))
);
export const getAllThreads = createSelector(
getMainThread,
getThreads,
(mainThread, threads) => {
const orderedThreads = Array.from(threads).sort((threadA, threadB) => {
if (threadA.name === threadB.name) {
return 0;
}
return threadA.name < threadB.name ? -1 : 1;
});
return [mainThread, ...orderedThreads].filter(Boolean);
}
);
export function getThread(state, threadActor) {
return getAllThreads(state).find(thread => thread.actor === threadActor);
}
// checks if a path begins with a thread actor
// e.g "server1.conn0.child1/workerTarget22/context1/dbg-workers.glitch.me"
export function startsWithThreadActor(state, path) {
const threadActors = getAllThreads(state).map(t => t.actor);
const match = path.match(new RegExp(`(${threadActors.join("|")})\/(.*)`));
return match?.[1];
}

Просмотреть файл

@ -53,6 +53,7 @@ export {
getSelectedFrames,
getVisibleSelectedFrame,
} from "./pause";
export * from "./threads";
import { objectInspector } from "devtools/client/shared/components/reps/index";

Просмотреть файл

@ -15,6 +15,7 @@ CompiledModules(
"isLineInScope.js",
"isSelectedFrameVisible.js",
"pause.js",
"threads.js",
"visibleBreakpoints.js",
"visibleColumnBreakpoints.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/>. */
import { createSelector } from "reselect";
export const getThreads = createSelector(
state => state.threads.threads,
threads => threads.filter(thread => !isMainThread(thread))
);
export const getAllThreads = createSelector(
getMainThread,
getThreads,
(mainThread, threads) => {
const orderedThreads = Array.from(threads).sort((threadA, threadB) => {
if (threadA.name === threadB.name) {
return 0;
}
return threadA.name < threadB.name ? -1 : 1;
});
return [mainThread, ...orderedThreads].filter(Boolean);
}
);
function isMainThread(thread) {
return thread.isTopLevel;
}
export function getMainThread(state) {
return state.threads.threads.find(isMainThread);
}
export function getDebuggeeUrl(state) {
return getMainThread(state)?.url || "";
}
export function getThread(state, threadActor) {
return getAllThreads(state).find(thread => thread.actor === threadActor);
}
// checks if a path begins with a thread actor
// e.g "server1.conn0.child1/workerTarget22/context1/dbg-workers.glitch.me"
export function startsWithThreadActor(state, path) {
const threadActors = getAllThreads(state).map(t => t.actor);
const match = path.match(new RegExp(`(${threadActors.join("|")})\/(.*)`));
return match?.[1];
}