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

Commit c95e086

Browse files
Łukasz SobekjasonLaster
authored andcommitted
Combines toJS calls in select.js (#5819)
1 parent 6352752 commit c95e086

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/actions/sources/select.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export function selectLocation(location: Location) {
9898
return;
9999
}
100100

101-
const source = getSource(getState(), location.sourceId);
102-
if (!source) {
101+
const sourceRecord = getSource(getState(), location.sourceId);
102+
if (!sourceRecord) {
103103
// If there is no source we deselect the current selected source
104104
return dispatch({ type: "CLEAR_SELECTED_SOURCE" });
105105
}
@@ -109,21 +109,23 @@ export function selectLocation(location: Location) {
109109
dispatch(closeActiveSearch());
110110
}
111111

112-
dispatch(addTab(source.toJS(), 0));
112+
const source = sourceRecord.toJS();
113113

114+
dispatch(addTab(source, 0));
114115
dispatch({
115116
type: "SELECT_SOURCE",
116-
source: source.toJS(),
117+
source,
117118
location
118119
});
119120

120-
await dispatch(loadSourceText(source));
121+
await dispatch(loadSourceText(sourceRecord));
121122
const selectedSource = getSelectedSource(getState());
122123
if (!selectedSource) {
123124
return;
124125
}
125126

126-
const sourceId = selectedSource.get("id");
127+
const sourceId = selectedSource.id;
128+
127129
if (
128130
prefs.autoPrettyPrint &&
129131
!getPrettySource(getState(), sourceId) &&
@@ -151,8 +153,8 @@ export function selectSpecificLocation(location: Location) {
151153
return;
152154
}
153155

154-
const source = getSource(getState(), location.sourceId);
155-
if (!source) {
156+
const sourceRecord = getSource(getState(), location.sourceId);
157+
if (!sourceRecord) {
156158
// If there is no source we deselect the current selected source
157159
return dispatch({ type: "CLEAR_SELECTED_SOURCE" });
158160
}
@@ -162,21 +164,22 @@ export function selectSpecificLocation(location: Location) {
162164
dispatch(closeActiveSearch());
163165
}
164166

165-
dispatch(addTab(source.toJS(), 0));
167+
const source = sourceRecord.toJS();
166168

169+
dispatch(addTab(source, 0));
167170
dispatch({
168171
type: "SELECT_SOURCE",
169-
source: source.toJS(),
172+
source,
170173
location
171174
});
172175

173-
await dispatch(loadSourceText(source));
176+
await dispatch(loadSourceText(sourceRecord));
174177
const selectedSource = getSelectedSource(getState());
175178
if (!selectedSource) {
176179
return;
177180
}
178181

179-
const sourceId = selectedSource.get("id");
182+
const sourceId = selectedSource.id;
180183
dispatch(setSymbols(sourceId));
181184
dispatch(setOutOfScopeLocations());
182185
};

src/actions/tests/tabs.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("closing tabs", () => {
2727
await dispatch(actions.selectLocation({ sourceId: "bar.js" }));
2828
dispatch(actions.closeTab("http://localhost:8000/examples/foo.js"));
2929

30-
expect(getSelectedSource(getState()).get("id")).toBe("bar.js");
30+
expect(getSelectedSource(getState()).id).toBe("bar.js");
3131
expect(getSourceTabs(getState()).size).toBe(1);
3232
});
3333

0 commit comments

Comments
 (0)