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

Commit

Permalink
Throttle new source
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonLaster committed Nov 20, 2017
1 parent 11dc316 commit f59026d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/actions/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ export function newSources(sources: Source[]) {
source => !getSource(getState(), source.id)
);

dispatch({
type: "ADD_SOURCES",
sources
});

for (const source of filteredSources) {
await dispatch(newSource(source));
await dispatch(loadSourceMap(source));
await checkSelectedSource(getState(), dispatch, source);
await checkPendingBreakpoints(getState(), dispatch, source.id);
}
};
}
Expand All @@ -113,7 +120,11 @@ export function newSources(sources: Source[]) {
*/
function loadSourceMap(generatedSource) {
return async function({ dispatch, getState, sourceMaps }: ThunkArgs) {
const urls = await sourceMaps.getOriginalURLs(generatedSource);
let urls = null;
try {
urls = await sourceMaps.getOriginalURLs(generatedSource);
} catch (e) {}

if (!urls) {
// If this source doesn't have a sourcemap, do nothing.
return;
Expand Down
12 changes: 11 additions & 1 deletion src/client/firefox/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
Actions
} from "./types";

import { throttle } from "lodash";
import { createPause, createSource } from "./create";
import { isEnabled } from "devtools-config";

Expand Down Expand Up @@ -61,8 +62,17 @@ function resumed(_: "resumed", packet: ResumedPacket) {
actions.resumed(packet);
}
let pendingSources = [];
const newSources = throttle(() => {
actions.newSources(
pendingSources.map(source => createSource(source, { supportsWasm }))
);
pendingSources = [];
}, 100);
function newSource(_: "newSource", { source }: SourcePacket) {
actions.newSource(createSource(source, { supportsWasm }));
pendingSources.push(source);
newSources();
if (isEnabled("eventListeners")) {
actions.fetchEventListeners();
Expand Down
2 changes: 1 addition & 1 deletion src/client/firefox/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export type ListTabsResponse = {
export type Actions = {
paused: Pause => void,
resumed: ResumedPacket => void,
newSource: Source => void,
newSources: (Source[]) => void,
fetchEventListeners: () => void
};

Expand Down

0 comments on commit f59026d

Please sign in to comment.