summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/pause/previewPausedLocation.js
blob: 7be462abfb34a92c7cf963a6d7fcc3c7bb418461 (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
/* 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 { selectLocation } from "../sources";
import { getContext, getSourceByURL } from "../../selectors";
import type { ThunkArgs } from "../types";
import type { URL } from "../../types";

type Location = {
  sourceUrl: URL,
  column: number,
  line: number,
};

export function previewPausedLocation(location: Location) {
  return ({ dispatch, getState }: ThunkArgs) => {
    const cx = getContext(getState());
    const source = getSourceByURL(getState(), location.sourceUrl);
    if (!source) {
      return;
    }

    const sourceLocation = {
      line: location.line,
      column: location.column,
      sourceId: source.id,
    };
    dispatch(selectLocation(cx, sourceLocation));

    dispatch({
      type: "PREVIEW_PAUSED_LOCATION",
      location: sourceLocation,
    });
  };
}

export function clearPreviewPausedLocation() {
  return {
    type: "CLEAR_PREVIEW_PAUSED_LOCATION",
  };
}