88 * Redux actions for the sources state
99 * @module actions/sources
1010 */
11+
12+ import { isGeneratedId } from "devtools-source-map" ;
13+ import { flatten } from "lodash" ;
14+
1115import { toggleBlackBox } from "./blackbox" ;
1216import { syncBreakpoint } from "../breakpoints" ;
1317import { loadSourceText } from "./loadSourceText" ;
1418import { togglePrettyPrint } from "./prettyPrint" ;
1519import { selectLocation } from "../sources" ;
1620import { getRawSourceURL , isPrettyURL } from "../../utils/source" ;
17-
1821import {
1922 getBlackBoxList ,
2023 getSource ,
@@ -40,20 +43,31 @@ function createOriginalSource(
4043 } ;
4144}
4245
46+ function loadSourceMaps ( sources ) {
47+ return async function ( { dispatch, getState, sourceMaps } : ThunkArgs ) {
48+ const originalSources = await Promise . all (
49+ sources . map ( source => dispatch ( loadSourceMap ( source . id ) ) )
50+ ) ;
51+
52+ await dispatch ( newSources ( flatten ( originalSources ) ) ) ;
53+ } ;
54+ }
55+
4356/**
4457 * @memberof actions/sources
4558 * @static
4659 */
47- function loadSourceMap ( generatedSourceId : SourceId ) {
60+ function loadSourceMap ( sourceId : SourceId ) {
4861 return async function ( { dispatch, getState, sourceMaps } : ThunkArgs ) {
49- const generatedSource = getSource ( getState ( ) , generatedSourceId ) . toJS ( ) ;
50- if ( ! generatedSource . sourceMapURL ) {
62+ const source = getSource ( getState ( ) , sourceId ) . toJS ( ) ;
63+
64+ if ( ! isGeneratedId ( sourceId ) || ! source . sourceMapURL ) {
5165 return ;
5266 }
5367
5468 let urls = null ;
5569 try {
56- urls = await sourceMaps . getOriginalURLs ( generatedSource ) ;
70+ urls = await sourceMaps . getOriginalURLs ( source ) ;
5771 } catch ( e ) {
5872 console . error ( e ) ;
5973 }
@@ -62,16 +76,12 @@ function loadSourceMap(generatedSourceId: SourceId) {
6276 // If this source doesn't have a sourcemap, enable it for pretty printing
6377 dispatch ( {
6478 type : "UPDATE_SOURCE" ,
65- source : { ...generatedSource , sourceMapURL : "" }
79+ source : { ...source , sourceMapURL : "" }
6680 } ) ;
6781 return ;
6882 }
6983
70- const originalSources = urls . map ( url =>
71- createOriginalSource ( url , generatedSource , sourceMaps )
72- ) ;
73-
74- dispatch ( newSources ( originalSources ) ) ;
84+ return urls . map ( url => createOriginalSource ( url , source , sourceMaps ) ) ;
7585 } ;
7686}
7787
@@ -154,7 +164,7 @@ export function newSource(source: Source) {
154164export function newSources ( sources : Source [ ] ) {
155165 return async ( { dispatch, getState } : ThunkArgs ) => {
156166 const filteredSources = sources . filter (
157- source => ! getSource ( getState ( ) , source . id )
167+ source => source && ! getSource ( getState ( ) , source . id )
158168 ) ;
159169
160170 if ( filteredSources . length == 0 ) {
@@ -171,11 +181,10 @@ export function newSources(sources: Source[]) {
171181 dispatch ( checkPendingBreakpoints ( source . id ) ) ;
172182 }
173183
174- await Promise . all (
175- filteredSources . map ( source => dispatch ( loadSourceMap ( source . id ) ) )
176- ) ;
184+ await dispatch ( loadSourceMaps ( filteredSources ) ) ;
185+
177186 // We would like to restore the blackboxed state
178187 // after loading all states to make sure the correctness.
179- dispatch ( restoreBlackBoxedSources ( filteredSources ) ) ;
188+ await dispatch ( restoreBlackBoxedSources ( filteredSources ) ) ;
180189 } ;
181190}
0 commit comments