Skip to content

Commit ff2bd33

Browse files
codehagjasonLaster
authored andcommitted
refactor loadSourcText (firefox-devtools#3853)
1 parent 3b1a61c commit ff2bd33

3 files changed

Lines changed: 43 additions & 36 deletions

File tree

src/actions/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as ast from "./ast";
1111
import * as coverage from "./coverage";
1212
import * as projectTextSearch from "./project-text-search";
1313
import * as sourceSearch from "./source-search";
14+
import * as loadSourceText from "./sources/loadSourceText";
1415

1516
export default Object.assign(
1617
{},
@@ -24,5 +25,6 @@ export default Object.assign(
2425
ast,
2526
coverage,
2627
projectTextSearch,
27-
sourceSearch
28+
sourceSearch,
29+
loadSourceText
2830
);

src/actions/sources.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { PROMISE } from "../utils/redux/middleware/promise";
1313
import assert from "../utils/assert";
1414
import { remapBreakpoints } from "./breakpoints";
1515

16-
import { setEmptyLines, setSymbols, setOutOfScopeLocations } from "./ast";
16+
import { setEmptyLines, setOutOfScopeLocations } from "./ast";
1717
import { syncBreakpoint } from "./breakpoints";
1818
import { searchSource } from "./project-text-search";
1919

2020
import { getPrettySourceURL, isLoaded } from "../utils/source";
2121
import { createPrettySource } from "./sources/createPrettySource";
22+
import { loadSourceText } from "./sources/loadSourceText";
2223

2324
import { prefs } from "../utils/prefs";
2425
import { removeDocument } from "../utils/editor";
@@ -356,40 +357,6 @@ export function toggleBlackBox(source: Source) {
356357
};
357358
}
358359

359-
/**
360-
* @memberof actions/sources
361-
* @static
362-
*/
363-
export function loadSourceText(source: Source) {
364-
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
365-
// Fetch the source text only once.
366-
if (source.text) {
367-
return Promise.resolve(source);
368-
}
369-
370-
await dispatch({
371-
type: "LOAD_SOURCE_TEXT",
372-
source: source,
373-
[PROMISE]: (async function() {
374-
if (sourceMaps.isOriginalId(source.id)) {
375-
return await sourceMaps.getOriginalSourceText(source);
376-
}
377-
378-
const response = await client.sourceContents(source.id);
379-
380-
return {
381-
id: source.id,
382-
text: response.source,
383-
contentType: response.contentType || "text/javascript"
384-
};
385-
})()
386-
});
387-
388-
await dispatch(setSymbols(source.id));
389-
await dispatch(setEmptyLines(source.id));
390-
};
391-
}
392-
393360
/**
394361
Load the text for all the avaliable sources
395362
* @memberof actions/sources
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @flow
2+
import { PROMISE } from "../../utils/redux/middleware/promise";
3+
import { setEmptyLines, setSymbols } from "../ast";
4+
import type { Source } from "../../types";
5+
import type { ThunkArgs } from "../types";
6+
/**
7+
* @memberof actions/sources
8+
* @static
9+
*/
10+
export function loadSourceText(source: Source) {
11+
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
12+
// Fetch the source text only once.
13+
if (source.text) {
14+
return Promise.resolve(source);
15+
}
16+
17+
await dispatch({
18+
type: "LOAD_SOURCE_TEXT",
19+
source: source,
20+
[PROMISE]: (async function() {
21+
if (sourceMaps.isOriginalId(source.id)) {
22+
return await sourceMaps.getOriginalSourceText(source);
23+
}
24+
25+
const response = await client.sourceContents(source.id);
26+
27+
return {
28+
id: source.id,
29+
text: response.source,
30+
contentType: response.contentType || "text/javascript"
31+
};
32+
})()
33+
});
34+
35+
await dispatch(setSymbols(source.id));
36+
await dispatch(setEmptyLines(source.id));
37+
};
38+
}

0 commit comments

Comments
 (0)