@@ -6,7 +6,7 @@ import { HashedSet } from 'data/model/immutable/HashedSet';
66import { HashReference } from 'data/model/immutable/HashReference' ;
77import { Logger , LogLevel } from 'util/logging' ;
88import { MultiMap } from 'util/multimap' ;
9- import { ClassRegistry } from 'data/model' ;
9+ import { ClassRegistry , Context , LiteralContext } from 'data/model' ;
1010import { BaseCollection , Collection , CollectionConfig , CollectionOp } from './Collection' ;
1111import { Identity } from 'data/identity' ;
1212
@@ -208,15 +208,46 @@ class MutableSet<T> extends BaseCollection<T> implements Collection<T> {
208208 }
209209
210210 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+
211223 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 ] ) )
214227 } ;
215228 }
216229
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 ) ] ) ) ;
220251 }
221252
222253 async validate ( references : Map < Hash , HashedObject > ) {
0 commit comments