mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
Bug 1515644 - [release 110] [sources] don't make newSources (a)wait on source maps to be loaded (#7302). r=davidwalsh
This commit is contained in:
parent
39f03906f2
commit
7008ec7816
@ -26,6 +26,7 @@ import {
|
|||||||
} from "../../selectors";
|
} from "../../selectors";
|
||||||
|
|
||||||
import { prefs } from "../../utils/prefs";
|
import { prefs } from "../../utils/prefs";
|
||||||
|
import sourceQueue from "../../utils/source-queue";
|
||||||
|
|
||||||
import type { Source, SourceId } from "../../types";
|
import type { Source, SourceId } from "../../types";
|
||||||
import type { Action, ThunkArgs } from "../types";
|
import type { Action, ThunkArgs } from "../types";
|
||||||
@ -46,20 +47,24 @@ function createOriginalSource(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadSourceMaps(sources) {
|
function loadSourceMaps(sources: Source[]) {
|
||||||
return async function({ dispatch, sourceMaps }: ThunkArgs) {
|
return async function({
|
||||||
|
dispatch,
|
||||||
|
sourceMaps
|
||||||
|
}: ThunkArgs): Promise<Promise<Source>[]> {
|
||||||
if (!prefs.clientSourceMapsEnabled) {
|
if (!prefs.clientSourceMapsEnabled) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let originalSources = await Promise.all(
|
return flatten(
|
||||||
sources.map(({ id }) => dispatch(loadSourceMap(id)))
|
await Promise.all(
|
||||||
|
sources.map(async ({ id }) => {
|
||||||
|
const originalSources = await dispatch(loadSourceMap(id));
|
||||||
|
sourceQueue.queueSources(originalSources);
|
||||||
|
return originalSources;
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
originalSources = flatten(originalSources).filter(Boolean);
|
|
||||||
if (originalSources.length > 0) {
|
|
||||||
await dispatch(newSources(originalSources));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,11 +73,15 @@ function loadSourceMaps(sources) {
|
|||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function loadSourceMap(sourceId: SourceId) {
|
function loadSourceMap(sourceId: SourceId) {
|
||||||
return async function({ dispatch, getState, sourceMaps }: ThunkArgs) {
|
return async function({
|
||||||
|
dispatch,
|
||||||
|
getState,
|
||||||
|
sourceMaps
|
||||||
|
}: ThunkArgs): Promise<Source[]> {
|
||||||
const source = getSource(getState(), sourceId);
|
const source = getSource(getState(), sourceId);
|
||||||
|
|
||||||
if (!source || isOriginal(source) || !source.sourceMapURL) {
|
if (!source || isOriginal(source) || !source.sourceMapURL) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let urls = null;
|
let urls = null;
|
||||||
@ -97,7 +106,7 @@ function loadSourceMap(sourceId: SourceId) {
|
|||||||
source: (({ ...currentSource, sourceMapURL: "" }: any): Source)
|
source: (({ ...currentSource, sourceMapURL: "" }: any): Source)
|
||||||
}: Action)
|
}: Action)
|
||||||
);
|
);
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls.map(url => createOriginalSource(url, source, sourceMaps));
|
return urls.map(url => createOriginalSource(url, source, sourceMaps));
|
||||||
@ -197,7 +206,7 @@ export function newSources(sources: Source[]) {
|
|||||||
|
|
||||||
dispatch(({ type: "ADD_SOURCES", sources: sources }: Action));
|
dispatch(({ type: "ADD_SOURCES", sources: sources }: Action));
|
||||||
|
|
||||||
await dispatch(loadSourceMaps(sources));
|
dispatch(loadSourceMaps(sources));
|
||||||
|
|
||||||
for (const source of sources) {
|
for (const source of sources) {
|
||||||
dispatch(checkSelectedSource(source.id));
|
dispatch(checkSelectedSource(source.id));
|
||||||
|
@ -32,7 +32,7 @@ function setupEvents(dependencies: Dependencies) {
|
|||||||
threadClient = dependencies.threadClient;
|
threadClient = dependencies.threadClient;
|
||||||
actions = dependencies.actions;
|
actions = dependencies.actions;
|
||||||
supportsWasm = dependencies.supportsWasm;
|
supportsWasm = dependencies.supportsWasm;
|
||||||
sourceQueue.initialize({ actions, supportsWasm, createSource });
|
sourceQueue.initialize(actions);
|
||||||
|
|
||||||
if (threadClient) {
|
if (threadClient) {
|
||||||
Object.keys(clientEvents).forEach(eventName => {
|
Object.keys(clientEvents).forEach(eventName => {
|
||||||
@ -98,7 +98,7 @@ function resumed(_: "resumed", packet: ResumedPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function newSource(_: "newSource", { source }: SourcePacket) {
|
function newSource(_: "newSource", { source }: SourcePacket) {
|
||||||
sourceQueue.queue(source);
|
sourceQueue.queue(createSource(source, { supportsWasm }));
|
||||||
}
|
}
|
||||||
|
|
||||||
function workerListChanged() {
|
function workerListChanged() {
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/>. */
|
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||||
|
|
||||||
|
// @flow
|
||||||
|
|
||||||
import { throttle } from "lodash";
|
import { throttle } from "lodash";
|
||||||
|
import type { Source } from "../types";
|
||||||
|
|
||||||
let newSources;
|
let newSources;
|
||||||
let createSource;
|
|
||||||
let supportsWasm = false;
|
|
||||||
let queuedSources;
|
let queuedSources;
|
||||||
let currentWork;
|
let currentWork;
|
||||||
|
|
||||||
@ -14,24 +15,25 @@ async function dispatchNewSources() {
|
|||||||
const sources = queuedSources;
|
const sources = queuedSources;
|
||||||
queuedSources = [];
|
queuedSources = [];
|
||||||
|
|
||||||
currentWork = await newSources(
|
currentWork = await newSources(sources);
|
||||||
sources.map(source => createSource(source, { supportsWasm }))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const queue = throttle(dispatchNewSources, 100);
|
const queue = throttle(dispatchNewSources, 100);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
initialize: options => {
|
initialize: (actions: Object) => {
|
||||||
newSources = options.actions.newSources;
|
newSources = actions.newSources;
|
||||||
createSource = options.createSource;
|
|
||||||
supportsWasm = options.supportsWasm;
|
|
||||||
queuedSources = [];
|
queuedSources = [];
|
||||||
},
|
},
|
||||||
queue: source => {
|
queue: (source: Source) => {
|
||||||
queuedSources.push(source);
|
queuedSources.push(source);
|
||||||
queue();
|
queue();
|
||||||
},
|
},
|
||||||
|
queueSources: (sources: Source[]) => {
|
||||||
|
queuedSources = queuedSources.concat(sources);
|
||||||
|
queue();
|
||||||
|
},
|
||||||
|
|
||||||
flush: () => Promise.all([queue.flush(), currentWork]),
|
flush: () => Promise.all([queue.flush(), currentWork]),
|
||||||
clear: () => queue.cancel()
|
clear: () => queue.cancel()
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user