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

Commit 74520c1

Browse files
ryanjduffyjasonLaster
authored andcommitted
Add stricter types for Breakpoint and AST actions (#5843)
1 parent 59645a0 commit 74520c1

File tree

10 files changed

+385
-300
lines changed

10 files changed

+385
-300
lines changed

src/actions/ast.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { PROMISE } from "./utils/middleware/promise";
2424
import { isGeneratedId } from "devtools-source-map";
2525

2626
import type { SourceId } from "../types";
27-
import type { ThunkArgs } from "./types";
27+
import type { ThunkArgs, Action } from "./types";
2828

2929
export function setSourceMetaData(sourceId: SourceId) {
3030
return async ({ dispatch, getState }: ThunkArgs) => {
@@ -34,13 +34,16 @@ export function setSourceMetaData(sourceId: SourceId) {
3434
}
3535

3636
const framework = await getFramework(source.id);
37-
dispatch({
38-
type: "SET_SOURCE_METADATA",
39-
sourceId: source.id,
40-
sourceMetaData: {
41-
framework
42-
}
43-
});
37+
38+
dispatch(
39+
({
40+
type: "SET_SOURCE_METADATA",
41+
sourceId: source.id,
42+
sourceMetaData: {
43+
framework
44+
}
45+
}: Action)
46+
);
4447
};
4548
}
4649

@@ -56,11 +59,13 @@ export function setSymbols(sourceId: SourceId) {
5659
return;
5760
}
5861

59-
await dispatch({
60-
type: "SET_SYMBOLS",
61-
source: source.toJS(),
62-
[PROMISE]: getSymbols(source.id)
63-
});
62+
await dispatch(
63+
({
64+
type: "SET_SYMBOLS",
65+
source: source.toJS(),
66+
[PROMISE]: getSymbols(source.id)
67+
}: Action)
68+
);
6469

6570
if (isPaused(getState())) {
6671
await dispatch(mapFrames());
@@ -85,11 +90,12 @@ export function setOutOfScopeLocations() {
8590
locations = await findOutOfScopeLocations(source.get("id"), location);
8691
}
8792

88-
dispatch({
89-
type: "OUT_OF_SCOPE_LOCATIONS",
90-
locations
91-
});
92-
93+
dispatch(
94+
({
95+
type: "OUT_OF_SCOPE_LOCATIONS",
96+
locations
97+
}: Action)
98+
);
9399
dispatch(setInScopeLines());
94100
};
95101
}
@@ -107,10 +113,12 @@ export function setPausePoints(sourceId: SourceId) {
107113
await client.setPausePoints(source.id, pausePoints);
108114
}
109115

110-
dispatch({
111-
type: "SET_PAUSE_POINTS",
112-
source: source.toJS(),
113-
pausePoints
114-
});
116+
dispatch(
117+
({
118+
type: "SET_PAUSE_POINTS",
119+
source: source.toJS(),
120+
pausePoints
121+
}: Action)
122+
);
115123
};
116124
}

src/actions/breakpoints.js

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { isEmptyLineInSource } from "../reducers/ast";
2424
// this will need to be changed so that addCLientBreakpoint is removed
2525
import { syncClientBreakpoint } from "./breakpoints/syncBreakpoint";
2626

27-
import type { ThunkArgs } from "./types";
27+
import type { ThunkArgs, Action } from "./types";
2828
import type { SourceId, PendingBreakpoint, Location } from "../types";
2929
import type { BreakpointsMap } from "../reducers/types";
3030

@@ -55,11 +55,13 @@ export function syncBreakpoint(
5555
pendingBreakpoint
5656
);
5757

58-
return dispatch({
59-
type: "SYNC_BREAKPOINT",
60-
breakpoint,
61-
previousLocation
62-
});
58+
return dispatch(
59+
({
60+
type: "SYNC_BREAKPOINT",
61+
breakpoint,
62+
previousLocation
63+
}: Action)
64+
);
6365
};
6466
}
6567

@@ -78,9 +80,18 @@ export function addBreakpoint(
7880
) {
7981
const breakpoint = createBreakpoint(location, { condition, hidden });
8082
return ({ dispatch, getState, sourceMaps, client }: ThunkArgs) => {
81-
const action = { type: "ADD_BREAKPOINT", breakpoint };
82-
const promise = addBreakpointPromise(getState, client, sourceMaps, action);
83-
return dispatch({ ...action, [PROMISE]: promise });
83+
return dispatch(
84+
({
85+
type: "ADD_BREAKPOINT",
86+
breakpoint,
87+
[PROMISE]: addBreakpointPromise(
88+
getState,
89+
client,
90+
sourceMaps,
91+
breakpoint
92+
)
93+
}: Action)
94+
);
8495
};
8596
}
8697

@@ -114,18 +125,23 @@ export function removeBreakpoint(location: Location) {
114125
// with the server. We just need to dispatch an action
115126
// simulating a successful server request
116127
if (bp.disabled) {
117-
return dispatch({
118-
type: "REMOVE_BREAKPOINT",
119-
breakpoint: bp,
120-
status: "done"
121-
});
128+
return dispatch(
129+
({
130+
type: "REMOVE_BREAKPOINT",
131+
breakpoint: bp,
132+
status: "done"
133+
}: Action)
134+
);
122135
}
123136

124-
return dispatch({
125-
type: "REMOVE_BREAKPOINT",
126-
breakpoint: bp,
127-
[PROMISE]: client.removeBreakpoint(bp.generatedLocation)
128-
});
137+
return dispatch(
138+
({
139+
type: "REMOVE_BREAKPOINT",
140+
breakpoint: bp,
141+
disabled: false,
142+
[PROMISE]: client.removeBreakpoint(bp.generatedLocation)
143+
}: Action)
144+
);
129145
};
130146
}
131147

@@ -144,13 +160,13 @@ export function enableBreakpoint(location: Location) {
144160
return;
145161
}
146162

147-
const action = { type: "ENABLE_BREAKPOINT", breakpoint };
148-
const promise = addBreakpointPromise(getState, client, sourceMaps, action);
149-
return dispatch({
163+
const action: Action = {
150164
type: "ENABLE_BREAKPOINT",
151165
breakpoint,
152-
[PROMISE]: promise
153-
});
166+
[PROMISE]: addBreakpointPromise(getState, client, sourceMaps, breakpoint)
167+
};
168+
169+
return dispatch(action);
154170
};
155171
}
156172

@@ -171,10 +187,12 @@ export function disableBreakpoint(location: Location) {
171187
await client.removeBreakpoint(bp.generatedLocation);
172188
const newBreakpoint = { ...bp, disabled: true };
173189

174-
return dispatch({
190+
const action: Action = {
175191
type: "DISABLE_BREAKPOINT",
176192
breakpoint: newBreakpoint
177-
});
193+
};
194+
195+
return dispatch(action);
178196
};
179197
}
180198

@@ -201,12 +219,21 @@ export function toggleAllBreakpoints(shouldDisableBreakpoints: boolean) {
201219
}
202220
}
203221

204-
return dispatch({
205-
type: shouldDisableBreakpoints
206-
? "DISABLE_ALL_BREAKPOINTS"
207-
: "ENABLE_ALL_BREAKPOINTS",
208-
breakpoints: modifiedBreakpoints
209-
});
222+
if (shouldDisableBreakpoints) {
223+
return dispatch(
224+
({
225+
type: "DISABLE_ALL_BREAKPOINTS",
226+
breakpoints: modifiedBreakpoints
227+
}: Action)
228+
);
229+
}
230+
231+
return dispatch(
232+
({
233+
type: "ENABLE_ALL_BREAKPOINTS",
234+
breakpoints: modifiedBreakpoints
235+
}: Action)
236+
);
210237
};
211238
}
212239

@@ -269,10 +296,12 @@ export function remapBreakpoints(sourceId: string) {
269296
sourceMaps
270297
);
271298

272-
return dispatch({
273-
type: "REMAP_BREAKPOINTS",
274-
breakpoints: newBreakpoints
275-
});
299+
return dispatch(
300+
({
301+
type: "REMAP_BREAKPOINTS",
302+
breakpoints: newBreakpoints
303+
}: Action)
304+
);
276305
};
277306
}
278307

@@ -318,10 +347,12 @@ export function setBreakpointCondition(
318347

319348
assertBreakpoint(newBreakpoint);
320349

321-
return dispatch({
322-
type: "SET_BREAKPOINT_CONDITION",
323-
breakpoint: newBreakpoint
324-
});
350+
return dispatch(
351+
({
352+
type: "SET_BREAKPOINT_CONDITION",
353+
breakpoint: newBreakpoint
354+
}: Action)
355+
);
325356
};
326357
}
327358

src/actions/breakpoints/addBreakpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default async function addBreakpoint(
1616
getState,
1717
client,
1818
sourceMaps,
19-
{ breakpoint }
19+
breakpoint
2020
) {
2121
const state = getState();
2222

src/actions/preview.js

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import { getMappedExpression } from "./expressions";
2424
import { isEqual } from "lodash";
2525

26-
import type { ThunkArgs } from "./types";
26+
import type { Action, ThunkArgs } from "./types";
2727
import type { Frame, ColumnPosition } from "../types";
2828
import type { AstLocation } from "../workers/parser";
2929

@@ -165,44 +165,46 @@ export function setPreview(
165165
cursorPos: any
166166
) {
167167
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
168-
await dispatch({
169-
type: "SET_PREVIEW",
170-
[PROMISE]: (async function() {
171-
const source = getSelectedSource(getState());
172-
173-
const sourceId = source.get("id");
174-
if (location && !isGeneratedId(sourceId)) {
175-
expression = await dispatch(getMappedExpression(expression));
176-
}
177-
178-
const selectedFrame = getSelectedFrame(getState());
179-
if (!selectedFrame) {
180-
return;
181-
}
182-
183-
const { result } = await client.evaluateInFrame(
184-
selectedFrame.id,
185-
expression
186-
);
187-
188-
if (result === undefined) {
189-
return;
190-
}
191-
192-
const extra = await dispatch(
193-
getExtra(expression, result, selectedFrame)
194-
);
195-
196-
return {
197-
expression,
198-
result,
199-
location,
200-
tokenPos,
201-
cursorPos,
202-
extra
203-
};
204-
})()
205-
});
168+
await dispatch(
169+
({
170+
type: "SET_PREVIEW",
171+
[PROMISE]: (async function() {
172+
const source = getSelectedSource(getState());
173+
174+
const sourceId = source.get("id");
175+
if (location && !isGeneratedId(sourceId)) {
176+
expression = await dispatch(getMappedExpression(expression));
177+
}
178+
179+
const selectedFrame = getSelectedFrame(getState());
180+
if (!selectedFrame) {
181+
return;
182+
}
183+
184+
const { result } = await client.evaluateInFrame(
185+
selectedFrame.id,
186+
expression
187+
);
188+
189+
if (result === undefined) {
190+
return;
191+
}
192+
193+
const extra = await dispatch(
194+
getExtra(expression, result, selectedFrame)
195+
);
196+
197+
return {
198+
expression,
199+
result,
200+
location,
201+
tokenPos,
202+
cursorPos,
203+
extra
204+
};
205+
})()
206+
}: Action)
207+
);
206208
};
207209
}
208210

@@ -213,8 +215,10 @@ export function clearPreview() {
213215
return;
214216
}
215217

216-
return dispatch({
217-
type: "CLEAR_SELECTION"
218-
});
218+
return dispatch(
219+
({
220+
type: "CLEAR_SELECTION"
221+
}: Action)
222+
);
219223
};
220224
}

0 commit comments

Comments
 (0)