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

Commit

Permalink
oof
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonLaster committed Aug 13, 2018
1 parent 0b62388 commit 47b9ede
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/actions/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../workers/parser";

import { clearWasmStates } from "../utils/wasm";
import { clearLoadSourceRequests } from "./sources/loadSourceText";

import type { Action, ThunkArgs } from "./types";

Expand All @@ -41,6 +42,7 @@ export function willNavigate(event: Object) {
clearASTs();
clearScopes();
clearSources();
clearLoadSourceRequests();
dispatch(navigate(event.url));
};
}
Expand Down
7 changes: 5 additions & 2 deletions src/actions/sources/loadSourceText.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import type { ThunkArgs } from "../types";

import type { Source } from "../../types";

const requests = new Map();
let requests = new Map();

export function clearLoadSourceRequests() {
requests = new Map();
}

// Measures the time it takes for a source to load
const loadSourceHistogram = "DEVTOOLS_DEBUGGER_LOAD_SOURCE_MS";
Expand Down Expand Up @@ -71,7 +75,6 @@ export function loadSourceText(source: Source) {
}

const newSource = getSourceFromId(getState(), source.id);

if (isOriginalId(newSource.id) && !newSource.isWasm) {
const generatedSource = getGeneratedSource(getState(), source);
await dispatch(loadSourceText(generatedSource));
Expand Down
27 changes: 20 additions & 7 deletions src/actions/sources/tests/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import { getSymbols } from "../../../reducers/ast";
import {
actions,
selectors,
Expand Down Expand Up @@ -143,30 +144,42 @@ describe("sources", () => {
});

it("should keep the generated the viewing context", async () => {
const { dispatch, getState } = createStore(sourceThreadClient);
const store = createStore(sourceThreadClient);
const { dispatch, getState } = store;
const baseSource = makeSource("base.js");
await dispatch(actions.newSource(baseSource));

await dispatch(
actions.selectLocation({ sourceId: baseSource.id, line: 1 })
);

expect(getSelectedSource(getState()).id).toBe(baseSource.id);
await waitForState(store, state => getSymbols(state, baseSource));
});

it("should keep the original the viewing context", async () => {
const { dispatch, getState } = createStore(
sourceThreadClient,
{},
{ getOriginalLocation: async location => ({ ...location, line: 12 }) }
{
getOriginalLocation: async location => ({ ...location, line: 12 }),
getGeneratedLocation: async location => ({ ...location, line: 12 }),
getOriginalSourceText: async () => ({ source: "" })
}
);

const baseSource = makeOriginalSource("base.js");
const baseSource = makeSource("base.js");
await dispatch(actions.newSource(baseSource));
await dispatch(actions.selectSource(baseSource.id));

await dispatch(
actions.selectLocation({ sourceId: baseSource.id, line: 1 })
);
const originalBaseSource = makeOriginalSource("base.js");
await dispatch(actions.newSource(originalBaseSource));

await dispatch(actions.selectSource(originalBaseSource.id));

const fooSource = makeSource("foo.js");
await dispatch(actions.newSource(fooSource));
await dispatch(actions.selectLocation({ sourceId: fooSource.id, line: 1 }));

expect(getSelectedLocation(getState()).line).toBe(12);
});

Expand Down
8 changes: 0 additions & 8 deletions src/reducers/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,6 @@ export function getGeneratedSource(state: OuterState, source: Source): Source {
return getSourceFromId(state, originalToGeneratedId(source.id));
}

export function getOriginalSource(state: OuterState, id: string) {
if (!isGeneratedId(source.id)) {
return source;
}

return getSourceInSources(getSources(state), generatedToOriginalId(id));
}

export function getPendingSelectedLocation(state: OuterState) {
return state.sources.pendingSelectedLocation;
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/tests-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import getConfig from "../../bin/getConfig";
import { readFileSync } from "fs";
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import { clearLoadSourceRequests } from "../actions/sources/loadSourceText";
import { setupHelper } from "../utils/dbg";

import { startSourceMapWorker, stopSourceMapWorker } from "devtools-source-map";
Expand Down Expand Up @@ -75,9 +76,10 @@ afterAll(() => {

afterEach(() => {});

beforeEach(() => {
beforeEach(async () => {
clearASTs();
clearSymbols();
clearLoadSourceRequests();
await clearSymbols();
clearHistory();
clearDocuments();

Expand Down

0 comments on commit 47b9ede

Please sign in to comment.