@@ -6,7 +6,7 @@ import { HashedSet } from 'data/model/immutable/HashedSet';
6
6
import { HashReference } from 'data/model/immutable/HashReference' ;
7
7
import { Logger , LogLevel } from 'util/logging' ;
8
8
import { MultiMap } from 'util/multimap' ;
9
- import { ClassRegistry } from 'data/model' ;
9
+ import { ClassRegistry , Context , LiteralContext } from 'data/model' ;
10
10
import { BaseCollection , Collection , CollectionConfig , CollectionOp } from './Collection' ;
11
11
import { Identity } from 'data/identity' ;
12
12
@@ -208,15 +208,46 @@ class MutableSet<T> extends BaseCollection<T> implements Collection<T> {
208
208
}
209
209
210
210
exportMutableState ( ) {
211
+
212
+ const literalElements = { } as any ;
213
+ const context = new Context ( ) ;
214
+
215
+ for ( const [ hash , elmt ] of this . _elements . entries ( ) ) {
216
+ if ( elmt instanceof HashedObject ) {
217
+ elmt . toContext ( context ) ;
218
+ } else {
219
+ literalElements [ hash ] = elmt ;
220
+ }
221
+ }
222
+
211
223
return {
212
- _elements : this . _elements ,
213
- _currentAddOpRefs : this . _currentAddOpRefs
224
+ _objectElements : context . toLiteralContext ( ) ,
225
+ _literalElements : literalElements ,
226
+ _currentAddOpRefs : Object . fromEntries ( [ ...this . _currentAddOpRefs . entries ( ) ] . map ( ( [ key , value ] ) => [ key , value . literalize ( ) . value ] ) )
214
227
} ;
215
228
}
216
229
217
- importMutableState ( state : any ) : void {
218
- this . _elements = new Map ( Object . entries ( state . _elements ) ) ;
219
- this . _currentAddOpRefs = new Map ( Object . entries ( state . _currentAddOpRefs ) ) ;
230
+ importMutableState ( state : {
231
+ _objectElements : LiteralContext ,
232
+ _literalElements : { [ key : string ] : any } ,
233
+ _currentAddOpRefs : { [ key : string ] : any }
234
+ } ) : void {
235
+
236
+ this . _elements = new Map ( ) ;
237
+
238
+ const context = new Context ( ) ;
239
+ context . fromLiteralContext ( state . _objectElements ) ;
240
+
241
+ for ( const hash of context . rootHashes ) {
242
+ this . _elements . set ( hash , HashedObject . fromContext ( context , hash ) as any as T ) ;
243
+ }
244
+
245
+ for ( const [ hash , literal ] of Object . entries ( state . _literalElements ) ) {
246
+ this . _elements . set ( hash , literal ) ;
247
+ }
248
+
249
+ const emptyContext = new Context ( ) ;
250
+ this . _currentAddOpRefs = new Map ( Object . entries ( state . _currentAddOpRefs ) . map ( ( [ key , value ] ) => [ key , HashedSet . deliteralize ( value , emptyContext ) ] ) ) ;
220
251
}
221
252
222
253
async validate ( references : Map < Hash , HashedObject > ) {
0 commit comments