summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/selectors/visibleBreakpoints.js
blob: 4a37a2433f12cefaceb76e7b8dbb5d901c7a8fe3 (plain)
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
/* 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 { createSelector } from "reselect";
import { uniqBy } from "lodash";

import { getBreakpointsList } from "../reducers/breakpoints";
import { getSelectedSource } from "../reducers/sources";

import { sortSelectedBreakpoints } from "../utils/breakpoint";
import { getSelectedLocation } from "../utils/selected-location";

import type { Breakpoint, Source } from "../types";
import type { Selector } from "../reducers/types";

/*
 * Finds the breakpoints, which appear in the selected source.
 */
export const getVisibleBreakpoints: Selector<?(Breakpoint[])> = createSelector(
  getSelectedSource,
  getBreakpointsList,
  (selectedSource: ?Source, breakpoints: Breakpoint[]) => {
    if (!selectedSource) {
      return null;
    }

    return breakpoints.filter(
      bp =>
        selectedSource &&
        getSelectedLocation(bp, selectedSource).sourceId === selectedSource.id
    );
  }
);

/*
 * Finds the first breakpoint per line, which appear in the selected source.
 */
export const getFirstVisibleBreakpoints: Selector<
  Breakpoint[]
> = createSelector(
  getVisibleBreakpoints,
  getSelectedSource,
  (breakpoints, selectedSource) => {
    if (!breakpoints || !selectedSource) {
      return [];
    }

    return (uniqBy(
      sortSelectedBreakpoints(breakpoints, selectedSource),
      bp => getSelectedLocation(bp, selectedSource).line
    ): any);
  }
);