forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebuggee.js
More file actions
95 lines (78 loc) · 2.38 KB
/
debuggee.js
File metadata and controls
95 lines (78 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 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/>. */
// @flow
/**
* Debuggee reducer
* @module reducers/debuggee
*/
import { sortBy } from "lodash";
import { createSelector } from "reselect";
import { getDisplayName } from "../utils/workers";
import type { Selector } from "./types";
import type { MainThread, WorkerList, Thread } from "../types";
import type { Action } from "../actions/types";
export type DebuggeeState = {
workers: WorkerList,
mainThread: MainThread
};
export function initialDebuggeeState(): DebuggeeState {
return {
workers: [],
mainThread: { actor: "", url: "", type: -1, name: "" }
};
}
export default function debuggee(
state: DebuggeeState = initialDebuggeeState(),
action: Action
): DebuggeeState {
switch (action.type) {
case "CONNECT":
return {
...state,
mainThread: { ...action.mainThread, name: L10N.getStr("mainThread") }
};
case "INSERT_WORKERS":
return insertWorkers(state, action.workers);
case "REMOVE_WORKERS":
const { workers } = action;
return {
...state,
workers: state.workers.filter(w => !workers.includes(w.actor))
};
case "NAVIGATE":
return {
...initialDebuggeeState(),
mainThread: action.mainThread
};
default:
return state;
}
}
function insertWorkers(state, workers) {
const formatedWorkers = workers.map(worker => ({
...worker,
name: getDisplayName(worker)
}));
return {
...state,
workers: [...state.workers, ...formatedWorkers]
};
}
export const getWorkers = (state: OuterState) => state.debuggee.workers;
export const getWorkerCount = (state: OuterState) => getWorkers(state).length;
export function getWorkerByThread(state: OuterState, thread: string) {
return getWorkers(state).find(worker => worker.actor == thread);
}
export function getMainThread(state: OuterState): MainThread {
return state.debuggee.mainThread;
}
export function getDebuggeeUrl(state: OuterState): string {
return getMainThread(state).url;
}
export const getThreads: Selector<Thread[]> = createSelector(
getMainThread,
getWorkers,
(mainThread, workers) => [mainThread, ...sortBy(workers, getDisplayName)]
);
type OuterState = { debuggee: DebuggeeState };