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

Commit

Permalink
Store pending requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonLaster committed Nov 17, 2017
1 parent b88c073 commit c47e09f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/actions/sources/loadSourceText.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { isLoaded, isLoading } from "../../utils/source";
import type { Source } from "../../types";
import type { ThunkArgs } from "../types";

const loadingSources = {};

async function loadSource(source: Source, { sourceMaps, client }) {
if (sourceMaps.isOriginalId(source.id)) {
return await sourceMaps.getOriginalSourceText(source);
Expand All @@ -33,16 +35,25 @@ async function loadSource(source: Source, { sourceMaps, client }) {
export function loadSourceText(source: Source) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
// Fetch the source text only once.
if (isLoaded(source) || isLoading(source)) {
if (isLoaded(source)) {
return Promise.resolve(source);
}

// Return the pending fetch
if (isLoading) {
return loadingSources[source.id];
}

loadingSources[source.id] = loadSource(source, { sourceMaps, client });

await dispatch({
type: "LOAD_SOURCE_TEXT",
source: source,
[PROMISE]: loadSource(source, { sourceMaps, client })
[PROMISE]: loadingSources
});

delete loadingSources[source.id];

const newSource = getSource(getState(), source.id).toJS();
if (newSource.isWasm) {
return;
Expand Down

0 comments on commit c47e09f

Please sign in to comment.