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

Commit acef4a1

Browse files
mmcotejasonLaster
authored andcommitted
Switched getExtraProps to use findClosestFunction to get the component name. (#5851)
1 parent bce7080 commit acef4a1

File tree

14 files changed

+109
-32
lines changed

14 files changed

+109
-32
lines changed

src/actions/ast.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
isPaused
1212
} from "../selectors";
1313

14-
import { mapFrames } from "./pause";
14+
import { mapFrames, setExtra } from "./pause";
15+
1516
import { setInScopeLines } from "./ast/setInScopeLines";
1617
import {
1718
getSymbols,
@@ -68,6 +69,7 @@ export function setSymbols(sourceId: SourceId) {
6869
);
6970

7071
if (isPaused(getState())) {
72+
await dispatch(setExtra());
7173
await dispatch(mapFrames());
7274
}
7375

src/actions/pause/fetchExtra.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+
// @flow
6+
7+
import { getSelectedFrame } from "../../selectors";
8+
import { getExtra } from "../preview";
9+
import type { ThunkArgs } from "../types";
10+
11+
export function fetchExtra() {
12+
return async function({ dispatch, getState }: ThunkArgs) {
13+
const frame = getSelectedFrame(getState());
14+
if (!frame) {
15+
return;
16+
}
17+
18+
const extra = await dispatch(getExtra("this;", frame.this, frame));
19+
dispatch({
20+
type: "ADD_EXTRA",
21+
extra: extra
22+
});
23+
};
24+
}

src/actions/pause/fetchScopes.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import { getSelectedFrame, getGeneratedFrameScope } from "../../selectors";
88
import { mapScopes } from "./mapScopes";
9-
import { getExtra } from "../preview";
109
import { PROMISE } from "../utils/middleware/promise";
11-
10+
import { setExtra } from "./setExtra";
1211
import type { ThunkArgs } from "../types";
1312

1413
export function fetchScopes() {
@@ -18,15 +17,13 @@ export function fetchScopes() {
1817
return;
1918
}
2019

21-
const extra = await dispatch(getExtra("this;", frame.this, frame));
22-
2320
const scopes = dispatch({
2421
type: "ADD_SCOPES",
2522
frame,
26-
extra,
2723
[PROMISE]: client.getFrameScopes(frame)
2824
});
2925

26+
await dispatch(setExtra());
3027
await dispatch(mapScopes(scopes, frame));
3128
};
3229
}

src/actions/pause/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export { resumed } from "./resumed";
2525
export { continueToHere } from "./continueToHere";
2626
export { breakOnNext } from "./breakOnNext";
2727
export { mapFrames } from "./mapFrames";
28+
export { setExtra } from "./setExtra";
2829
export { setPopupObjectProperties } from "./setPopupObjectProperties";
2930
export { pauseOnExceptions } from "./pauseOnExceptions";
3031
export { selectFrame } from "./selectFrame";

src/actions/pause/mapFrames.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export function mapDisplayNames(frames: Frame[], getState: () => State) {
3737
return frame;
3838
}
3939

40-
const originalFunction = findClosestFunction(
41-
symbols.functions,
42-
frame.location
43-
);
40+
const originalFunction = findClosestFunction(symbols, frame.location);
4441

4542
if (!originalFunction) {
4643
return frame;

src/actions/pause/setExtra.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @flow
2+
3+
import { getSymbols, getSource, getSelectedFrame } from "../../selectors";
4+
import { fetchExtra } from "./fetchExtra";
5+
6+
import type { ThunkArgs } from "../types";
7+
8+
export function setExtra() {
9+
return async function({ dispatch, getState, sourceMaps }: ThunkArgs) {
10+
const frame = getSelectedFrame(getState());
11+
const source = getSource(getState(), frame.location.sourceId);
12+
const symbols = getSymbols(getState(), source);
13+
14+
if (symbols && symbols.classes) {
15+
dispatch(fetchExtra());
16+
}
17+
};
18+
}

src/actions/preview.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { findBestMatchExpression } from "../utils/ast";
7+
import { findBestMatchExpression, findClosestClass } from "../utils/ast";
88
import { getTokenLocation } from "../utils/editor";
99
import { isReactComponent, isImmutable, isConsole } from "../utils/preview";
1010
import { isGeneratedId } from "devtools-source-map";
@@ -17,7 +17,8 @@ import {
1717
getSelectedSource,
1818
getSelectedFrame,
1919
getSymbols,
20-
getCanRewind
20+
getCanRewind,
21+
getSource
2122
} from "../selectors";
2223

2324
import { getMappedExpression } from "./expressions";
@@ -52,10 +53,24 @@ async function getImmutableProps(expression: string, evaluate) {
5253
};
5354
}
5455

55-
async function getExtraProps(expression, result, evaluate) {
56+
async function getExtraProps(getState, expression, result, evaluate) {
5657
const props = {};
5758
if (isReactComponent(result)) {
58-
props.react = await getReactProps(evaluate);
59+
const selectedFrame = getSelectedFrame(getState());
60+
const source = getSource(getState(), selectedFrame.location.sourceId);
61+
const symbols = getSymbols(getState(), source);
62+
63+
if (symbols && symbols.classes) {
64+
const originalClass = findClosestClass(symbols, selectedFrame.location);
65+
66+
if (originalClass) {
67+
props.react = { displayName: originalClass.name };
68+
}
69+
}
70+
71+
if (!props.react) {
72+
props.react = await getReactProps(evaluate);
73+
}
5974
}
6075

6176
if (isImmutable(result)) {
@@ -95,7 +110,7 @@ export function getExtra(
95110
selectedFrame: Frame
96111
) {
97112
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
98-
const extra = await getExtraProps(expression, result, expr =>
113+
const extra = await getExtraProps(getState, expression, result, expr =>
99114
client.evaluateInFrame(selectedFrame.id, expr)
100115
);
101116

src/actions/types.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,13 @@ type PauseAction =
316316
type: "MAP_FRAMES",
317317
frames: Frame[]
318318
|}
319+
| {|
320+
type: "ADD_EXTRA",
321+
extra: any
322+
|}
319323
| {|
320324
type: "ADD_SCOPES",
321325
frame: Frame,
322-
extra: any,
323326
status: AsyncStatus,
324327
value: Scope
325328
|};

src/components/Editor/EditorMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export default connect(
251251
getSymbols(state, selectedSource)
252252
),
253253
getFunctionLocation: line =>
254-
findClosestFunction(getSymbols(state, selectedSource).functions, {
254+
findClosestFunction(getSymbols(state, selectedSource), {
255255
line,
256256
column: Infinity
257257
})

src/reducers/pause.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ function update(
130130
return { ...state, frames: action.frames };
131131
}
132132

133+
case "ADD_EXTRA": {
134+
return { ...state, extra: action.extra };
135+
}
136+
133137
case "ADD_SCOPES": {
134-
const { frame, extra, status, value } = action;
138+
const { frame, status, value } = action;
135139
const selectedFrameId = frame.id;
136140

137141
const generated = {
@@ -143,7 +147,6 @@ function update(
143147
};
144148
return {
145149
...state,
146-
extra: extra,
147150
frameScopes: {
148151
...state.frameScopes,
149152
generated

0 commit comments

Comments
 (0)