Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 2216221

Browse files
committed
Refactor pause commands (#5804)
1 parent 5341396 commit 2216221

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/actions/pause/commands.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ import { addHiddenBreakpoint } from "../breakpoints";
1212
import { features } from "../../utils/prefs";
1313

1414
import type { ThunkArgs } from "../types";
15-
type CommandType =
16-
| "stepOver"
17-
| "stepIn"
18-
| "stepOut"
19-
| "resume"
20-
| "rewind"
21-
| "reverseStepOver"
22-
| "reverseStepIn"
23-
| "reverseStepOut";
15+
import type { Command } from "../../reducers/types";
2416

2517
/**
2618
* Debugger commands like stepOver, stepIn, stepUp
@@ -29,7 +21,7 @@ type CommandType =
2921
* @memberof actions/pause
3022
* @static
3123
*/
32-
export function command(type: CommandType) {
24+
export function command(type: Command) {
3325
return async ({ dispatch, client }: ThunkArgs) => {
3426
return dispatch({
3527
type: "COMMAND",
@@ -179,7 +171,7 @@ function hasAwait(source, pauseLocation) {
179171
* @param stepType
180172
* @returns {function(ThunkArgs)}
181173
*/
182-
export function astCommand(stepType: CommandType) {
174+
export function astCommand(stepType: Command) {
183175
return async ({ dispatch, getState, sourceMaps }: ThunkArgs) => {
184176
if (!features.asyncStepping) {
185177
return dispatch(command(stepType));

src/actions/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
Worker
1717
} from "../types";
1818

19-
import type { State } from "../reducers/types";
19+
import type { State, Command } from "../reducers/types";
2020

2121
import type {
2222
ActiveSearchType,
@@ -264,7 +264,7 @@ type PauseAction =
264264
shouldPauseOnExceptions: boolean,
265265
shouldIgnoreCaughtExceptions: boolean
266266
}
267-
| { type: "COMMAND", value: { type: string }, command: string }
267+
| { type: "COMMAND", status: AsyncStatus, command: Command }
268268
| { type: "SELECT_FRAME", frame: Frame }
269269
| {
270270
type: "SET_POPUP_OBJECT_PROPERTIES",

src/reducers/pause.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ import type { OriginalScope } from "../actions/pause/mapScopes";
1919
import type { Action } from "../actions/types";
2020
import type { Why, Scope, SourceId, FrameId, Location } from "../types";
2121

22+
export type Command =
23+
| null
24+
| "stepOver"
25+
| "stepIn"
26+
| "stepOut"
27+
| "resume"
28+
| "rewind"
29+
| "reverseStepOver"
30+
| "reverseStepIn"
31+
| "reverseStepOut"
32+
| "expression";
33+
2234
export type PauseState = {
2335
why: ?Why,
2436
isWaitingOnBreak: boolean,
@@ -48,7 +60,7 @@ export type PauseState = {
4860
shouldIgnoreCaughtExceptions: boolean,
4961
canRewind: boolean,
5062
debuggeeUrl: string,
51-
command: string,
63+
command: Command,
5264
previousLocation: ?{
5365
location: Location,
5466
generatedLocation: Location
@@ -70,7 +82,7 @@ export const createPauseState = (): PauseState => ({
7082
shouldIgnoreCaughtExceptions: prefs.ignoreCaughtExceptions,
7183
canRewind: false,
7284
debuggeeUrl: "",
73-
command: "",
85+
command: null,
7486
previousLocation: null
7587
});
7688

@@ -217,7 +229,7 @@ function update(
217229
command: action.command,
218230
previousLocation: buildPreviousLocation(state, action)
219231
}
220-
: { ...state, command: "" };
232+
: { ...state, command: null };
221233
}
222234

223235
case "RESUME":
@@ -228,7 +240,7 @@ function update(
228240
case "EVALUATE_EXPRESSION":
229241
return {
230242
...state,
231-
command: action.status === "start" ? "expression" : ""
243+
command: action.status === "start" ? "expression" : null
232244
};
233245

234246
case "NAVIGATE":
@@ -278,8 +290,12 @@ export function getPauseReason(state: OuterState): ?Why {
278290
return state.pause.why;
279291
}
280292

293+
export function getPauseCommand(state: OuterState): Command {
294+
return state.pause && state.pause.command;
295+
}
296+
281297
export function isStepping(state: OuterState) {
282-
return ["stepIn", "stepOver", "stepOut"].includes(state.pause.command);
298+
return ["stepIn", "stepOver", "stepOut"].includes(getPauseCommand(state));
283299
}
284300

285301
export function isPaused(state: OuterState) {

src/reducers/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ export type { SourcesMap } from "./sources";
3535
export type { ActiveSearchType, OrientationType } from "./ui";
3636
export type { BreakpointsMap } from "./breakpoints";
3737
export type { WorkersList } from "./debuggee";
38+
export type { Command } from "./pause";

0 commit comments

Comments
 (0)