Skip to content

Commit 1ef1a4b

Browse files
sharathnarayanphcodehag
authored andcommitted
[Sources] - switch to loaded state (firefox-devtools#3740)
* SourceState changes completed * SourceState test case changes * removed isLoaded/ removed toJS() * removed loadedState * Modified utils/Referred isLoaded in test * fix tests * fixup mochi
1 parent 48abb2c commit 1ef1a4b

19 files changed

Lines changed: 429 additions & 409 deletions

File tree

flow-typed/debugger-html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ declare module "debugger-html" {
210210
text?: string,
211211
contentType?: string,
212212
error?: string,
213-
loading?: boolean
213+
loadedState: "unloaded" | "loading" | "loaded"
214214
};
215215

216216
/**

src/actions/sources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { setSymbols, setOutOfScopeLocations } from "./ast";
1717
import { syncBreakpoint } from "./breakpoints";
1818
import { searchSource } from "./project-text-search";
1919

20-
import { getPrettySourceURL } from "../utils/source";
20+
import { getPrettySourceURL, isLoaded } from "../utils/source";
2121
import { createPrettySource } from "./sources/createPrettySource";
2222

2323
import { prefs } from "../utils/prefs";
@@ -303,7 +303,7 @@ export function togglePrettyPrint(sourceId: string) {
303303
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
304304
const source = getSource(getState(), sourceId).toJS();
305305

306-
if (source && source.loading) {
306+
if (source && !isLoaded(source)) {
307307
return {};
308308
}
309309

src/actions/sources/createPrettySource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createPrettySource(sourceId) {
2828
text: code,
2929
contentType: "text/javascript",
3030
frames,
31-
loading: false
31+
loadedState: "loaded"
3232
};
3333

3434
return dispatch({

src/actions/sources/tests/__snapshots__/createPrettySource.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Immutable.Map {
99
",
1010
contentType: "text/javascript",
1111
frames: undefined,
12-
loading: false,
12+
loadedState: "loaded",
1313
}
1414
`;

src/actions/tests/sources.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe("sources", () => {
142142
// Don't block on this so we can check the loading state.
143143
dispatch(actions.loadSourceText({ id: "foo1" }));
144144
const fooSource = getSource(getState(), "foo1");
145-
expect(fooSource.get("loading")).toEqual(true);
145+
expect(fooSource.get("loadedState")).toEqual("loading");
146146
});
147147

148148
it("should indicate an errored source text", async () => {

src/client/firefox/create.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export function createSource(
4141
isPrettyPrinted: false,
4242
isWasm: supportsWasm && source.introductionType === "wasm",
4343
sourceMapURL: source.sourceMapURL,
44-
isBlackBoxed: false
44+
isBlackBoxed: false,
45+
loadedState: "unloaded"
4546
};
4647
}
4748

src/components/Editor/Breakpoints.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import actions from "../../actions";
88
import { getSelectedSource } from "../../selectors";
99
import getVisibleBreakpoints from "../../selectors/visibleBreakpoints";
1010
import { makeLocationId } from "../../utils/breakpoint";
11+
import { isLoaded } from "../../utils/source";
1112

1213
import type { SourceRecord, BreakpointsMap } from "../../reducers/types";
1314

@@ -21,7 +22,10 @@ class Breakpoints extends Component {
2122
props: props;
2223

2324
shouldComponentUpdate(nextProps: any) {
24-
if (nextProps.selectedSource && nextProps.selectedSource.get("loading")) {
25+
if (
26+
nextProps.selectedSource &&
27+
!isLoaded(nextProps.selectedSource.toJS())
28+
) {
2529
return false;
2630
}
2731

src/components/Editor/Footer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Svg from "../shared/Svg";
1111

1212
import classnames from "classnames";
1313
import { isEnabled } from "devtools-config";
14-
import { isPretty } from "../../utils/source";
14+
import { isPretty, isLoaded } from "../../utils/source";
1515
import { shouldShowFooter, shouldShowPrettyPrint } from "../../utils/editor";
1616

1717
import PaneToggleButton from "../shared/Button/PaneToggle";
@@ -35,7 +35,7 @@ class SourceFooter extends PureComponent {
3535

3636
prettyPrintButton() {
3737
const { selectedSource, togglePrettyPrint } = this.props;
38-
const sourceLoaded = selectedSource && !selectedSource.get("loading");
38+
const sourceLoaded = selectedSource && isLoaded(selectedSource.toJS());
3939

4040
if (!shouldShowPrettyPrint(selectedSource)) {
4141
return;
@@ -62,7 +62,7 @@ class SourceFooter extends PureComponent {
6262

6363
blackBoxButton() {
6464
const { selectedSource, toggleBlackBox } = this.props;
65-
const sourceLoaded = selectedSource && !selectedSource.get("loading");
65+
const sourceLoaded = selectedSource && isLoaded(selectedSource.toJS());
6666

6767
const blackboxed = selectedSource.get("isBlackBoxed");
6868

src/components/Editor/SearchBar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { find, findNext, findPrev, removeOverlay } from "../../utils/editor";
1717

1818
import { getMatches } from "../../utils/search";
19+
import { isLoaded } from "../../utils/source";
1920

2021
import { scrollList } from "../../utils/result-list";
2122
import classnames from "classnames";
@@ -144,9 +145,9 @@ class SearchBar extends Component {
144145
scrollList(this.refs.resultList.refs, this.state.selectedResultIndex);
145146
}
146147

147-
const hasLoaded = selectedSource && !selectedSource.get("loading");
148+
const hasLoaded = selectedSource && isLoaded(selectedSource.toJS());
148149
const wasLoading =
149-
prevProps.selectedSource && prevProps.selectedSource.get("loading");
150+
prevProps.selectedSource && isLoaded(prevProps.selectedSource.toJS());
150151

151152
const doneLoading = wasLoading && hasLoaded;
152153
const changedFiles =

src/components/Editor/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import GutterMenu from "./GutterMenu";
1010
import EditorMenu from "./EditorMenu";
1111
import { renderConditionalPanel } from "./ConditionalPanel";
1212
import { debugGlobal } from "devtools-launchpad";
13+
import { isLoaded } from "../../utils/source";
1314

1415
import {
1516
getActiveSearchState,
@@ -109,7 +110,7 @@ class Editor extends PureComponent {
109110
if (this.props.selectedSource) {
110111
this.showMessage("");
111112
}
112-
} else if (selectedSource.get("loading")) {
113+
} else if (!isLoaded(selectedSource.toJS())) {
113114
this.showMessage(L10N.getStr("loadingText"));
114115
} else if (selectedSource.get("error")) {
115116
this.showMessage(selectedSource.get("error"));
@@ -527,7 +528,7 @@ class Editor extends PureComponent {
527528

528529
if (
529530
!selectedSource ||
530-
selectedSource.get("loading") ||
531+
!isLoaded(selectedSource.toJS()) ||
531532
!hitCount ||
532533
!this.state.editor
533534
) {

0 commit comments

Comments
 (0)