forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreakpointSources.js
More file actions
65 lines (55 loc) · 1.76 KB
/
Copy pathbreakpointSources.js
File metadata and controls
65 lines (55 loc) · 1.76 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
/* 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
import { sortBy, uniq } from "lodash";
import { createSelector } from "reselect";
import { getSources, getBreakpoints } from "../selectors";
import { getFilename } from "../utils/source";
import type { Source, Breakpoint } from "../types";
import type { SourcesMap, BreakpointsMap } from "../reducers/types";
export type BreakpointSources = Array<{
source: Source,
breakpoints: Breakpoint[]
}>;
function getBreakpointsForSource(
source: Source,
breakpoints: BreakpointsMap
): Breakpoint[] {
const bpList = breakpoints.valueSeq();
return bpList
.filter(
bp =>
bp.location.sourceId == source.id &&
!bp.hidden &&
(bp.text || bp.originalText || bp.condition || bp.disabled)
)
.sortBy(bp => bp.location.line)
.toJS();
}
function findBreakpointSources(
sources: SourcesMap,
breakpoints: BreakpointsMap
): Source[] {
const sourceIds: string[] = uniq(
breakpoints
.valueSeq()
.map(bp => bp.location.sourceId)
.toJS()
);
const breakpointSources = sourceIds
.map(id => sources[id])
.filter(source => source && !source.isBlackBoxed);
return sortBy(breakpointSources, (source: Source) => getFilename(source));
}
export const getBreakpointSources = createSelector(
getBreakpoints,
getSources,
(breakpoints: BreakpointsMap, sources: SourcesMap) =>
findBreakpointSources(sources, breakpoints)
.map(source => ({
source,
breakpoints: getBreakpointsForSource(source, breakpoints)
}))
.filter(({ breakpoints: bpSources }) => bpSources.length > 0)
);