@@ -47,6 +47,19 @@ export function initialSourcesState(): Record<SourcesState> {
4747 ) ( ) ;
4848}
4949
50+ export const SourceRecordClass = new I . Record ( {
51+ id : undefined ,
52+ url : undefined ,
53+ sourceMapURL : undefined ,
54+ isBlackBoxed : false ,
55+ isPrettyPrinted : false ,
56+ isWasm : false ,
57+ text : undefined ,
58+ contentType : "" ,
59+ error : undefined ,
60+ loadedState : "unloaded"
61+ } ) ;
62+
5063function update (
5164 state : Record < SourcesState > = initialSourcesState ( ) ,
5265 action : Action
@@ -60,7 +73,8 @@ function update(
6073 }
6174
6275 case "ADD_SOURCE" : {
63- return updateSource ( state , action . source ) ;
76+ const source = action . source ;
77+ return updateSource ( state , source ) ;
6478 }
6579
6680 case "ADD_SOURCES" : {
@@ -133,7 +147,7 @@ function update(
133147
134148 case "NAVIGATE" :
135149 const source = getSelectedSource ( { sources : state } ) ;
136- const url = source && source . get ( " url" ) ;
150+ const url = source && source . url ;
137151
138152 if ( ! url ) {
139153 return initialSourcesState ( ) ;
@@ -174,8 +188,13 @@ function updateSource(state: Record<SourcesState>, source: Source | Object) {
174188 if ( ! source . id ) {
175189 return state ;
176190 }
191+ const existingSource = state . getIn ( [ "sources" , source . id ] ) ;
177192
178- return state . mergeIn ( [ "sources" , source . id ] , source ) ;
193+ if ( existingSource ) {
194+ const updatedSource = existingSource . merge ( source ) ;
195+ return state . setIn ( [ "sources" , source . id ] , updatedSource ) ;
196+ }
197+ return state . setIn ( [ "sources" , source . id ] , new SourceRecordClass ( source ) ) ;
179198}
180199
181200export function removeSourceFromTabList ( tabs : any , url : string ) {
@@ -201,7 +220,7 @@ function restoreTabs() {
201220 * @static
202221 */
203222function updateTabList ( state : OuterState , url : ?string , tabIndex ?: number ) {
204- let tabs = state . sources . get ( " tabs" ) ;
223+ let tabs = state . sources . tabs ;
205224
206225 const urlIndex = tabs . indexOf ( url ) ;
207226 const includesUrl = ! ! tabs . find ( tab => tab == url ) ;
@@ -238,20 +257,18 @@ export function getNewSelectedSourceId(
238257
239258 const selectedTab = state . sources . sources . get ( selectedLocation . sourceId ) ;
240259
241- const selectedTabUrl = selectedTab ? selectedTab . get ( " url" ) : "" ;
260+ const selectedTabUrl = selectedTab ? selectedTab . url : "" ;
242261
243262 if ( availableTabs . includes ( selectedTabUrl ) ) {
244263 const sources = state . sources . sources ;
245264 if ( ! sources ) {
246265 return "" ;
247266 }
248267
249- const selectedSource = sources . find (
250- source => source . get ( "url" ) == selectedTabUrl
251- ) ;
268+ const selectedSource = sources . find ( source => source . url == selectedTabUrl ) ;
252269
253270 if ( selectedSource ) {
254- return selectedSource . get ( "id" ) ;
271+ return selectedSource . id ;
255272 }
256273
257274 return "" ;
@@ -268,7 +285,7 @@ export function getNewSelectedSourceId(
268285 ) ;
269286
270287 if ( tabSource ) {
271- return tabSource . get ( "id" ) ;
288+ return tabSource . id ;
272289 }
273290
274291 return "" ;
@@ -312,7 +329,7 @@ export function getPrettySource(state: OuterState, id: string) {
312329 return ;
313330 }
314331
315- return getSourceByURL ( state , getPrettySourceURL ( source . get ( " url" ) ) ) ;
332+ return getSourceByURL ( state , getPrettySourceURL ( source . url ) ) ;
316333}
317334
318335export function hasPrettySource ( state : OuterState , id : string ) {
@@ -324,7 +341,7 @@ function getSourceByUrlInSources(sources: SourcesMap, url: string) {
324341 return null ;
325342 }
326343
327- return sources . find ( source => source . get ( " url" ) === url ) ;
344+ return sources . find ( source => source . url === url ) ;
328345}
329346
330347export function getSourceInSources (
@@ -378,7 +395,7 @@ export const getSelectedSourceText = createSelector(
378395 getSelectedSource ,
379396 getSourcesState ,
380397 ( selectedSource , sources ) => {
381- const id = selectedSource . get ( "id" ) ;
398+ const id = selectedSource . id ;
382399 return id ? sources . sourcesText . get ( id ) : null ;
383400 }
384401) ;
0 commit comments