@@ -42,9 +42,6 @@ function serializeLoadedData(loadedDataSources: Array<LoadedData>) {
4242 return dataSourceToId . get ( ds ) ! ;
4343 }
4444
45- const id = nextId ( ) ;
46- dataSourceToId . set ( ds , id ) ;
47-
4845 // don't need to serialize all parents, just the ones that are necessary.
4946 const { type } = ds ;
5047 if ( type === 'file' ) {
@@ -53,6 +50,9 @@ function serializeLoadedData(loadedDataSources: Array<LoadedData>) {
5350 return serializeDataSource ( ds . parent ) ;
5451 }
5552
53+ const id = nextId ( ) ;
54+ dataSourceToId . set ( ds , id ) ;
55+
5656 const fileId = nextId ( ) ;
5757 files [ fileId ] = ds . file ;
5858 serializedDependencies . push ( {
@@ -61,38 +61,58 @@ function serializeLoadedData(loadedDataSources: Array<LoadedData>) {
6161 fileId,
6262 fileType : ds . fileType ,
6363 } ) ;
64- } else if ( type === 'archive' ) {
64+ return id ;
65+ }
66+
67+ if ( type === 'archive' ) {
68+ const parentId = serializeDataSource ( ds . parent ) ;
69+ const id = nextId ( ) ;
70+ dataSourceToId . set ( ds , id ) ;
71+
6572 serializedDependencies . push ( {
6673 id,
6774 type : 'archive' ,
6875 path : ds . path ,
69- parent : serializeDataSource ( ds . parent ) ,
76+ parent : parentId ,
7077 } ) ;
71- } else if ( type === 'uri' ) {
78+ return id ;
79+ }
80+
81+ if ( type === 'uri' ) {
82+ const id = nextId ( ) ;
83+ dataSourceToId . set ( ds , id ) ;
84+
7285 serializedDependencies . push ( {
7386 id,
7487 type : 'uri' ,
7588 name : ds . name ,
7689 uri : ds . uri ,
7790 mime : ds . mime ,
7891 } ) ;
79- } else if ( type === 'collection' ) {
92+ return id ;
93+ }
94+
95+ if ( type === 'collection' ) {
96+ const id = nextId ( ) ;
97+ dataSourceToId . set ( ds , id ) ;
98+
8099 serializedDependencies . push ( {
81100 id,
82101 type : 'collection' ,
83102 sources : ds . sources . map ( ( src ) => serializeDataSource ( src ) ) ,
84103 } ) ;
85- } else if ( type === 'chunk' ) {
104+ return id ;
105+ }
106+
107+ if ( type === 'chunk' ) {
86108 // chunk derives from the parent. Just return the serialized parent.
87109 if ( ds . parent ) {
88110 return serializeDataSource ( ds . parent ) ;
89111 }
90112 throw new Error ( 'Chunk does not have a parent' ) ;
91- } else {
92- throw new Error ( `Invalid data source type: ${ type as string } ` ) ;
93113 }
94114
95- return id ;
115+ throw new Error ( `Invalid data source type: ${ type as string } ` ) ;
96116 }
97117
98118 loadedDataSources . forEach ( ( { dataID, dataSource } ) => {
0 commit comments