@@ -85,9 +85,7 @@ export interface MemoryVersionable {
8585 getSlice : ( ) => object ;
8686 getSliceValue : ( ID : ProxyUniqID ) => MemoryCompiled ;
8787 isFrozen : ( ) => boolean ;
88- isDirty : ( ID : ProxyUniqID ) => boolean ;
8988 markDirty : ( ID : ProxyUniqID ) => void ;
90- markAsLoaded : ( ID : ProxyUniqID ) => boolean ;
9189 addSliceProxyParent : ( ID : ProxyUniqID , parentID : ProxyUniqID , attributeName : string ) => boolean ;
9290 deleteSliceProxyParent : (
9391 ID : ProxyUniqID ,
@@ -140,7 +138,6 @@ export class Memory {
140138 _sliceKey : sliceKey ; // identifier or current memory slice
141139 _references : Record < sliceKey , MemoryReference > = { } ; // Record<children, parent>
142140 _currentReference : MemoryReference ; // Record<children, parent>
143- _invalideCache : Record < number , boolean > = { } ; // paths which have been set but not read again yet (after the set)
144141 _proxies : Record < number , object > = { } ;
145142 _rootProxies : Record < number , boolean > = { } ;
146143 _memoryVersionable : MemoryVersionable ;
@@ -157,16 +154,10 @@ export class Memory {
157154 getSlice : ( ) : Record < number , MemoryType > => this . _currentReference . slice ,
158155 getSliceValue : ( ID : ProxyUniqID ) : MemoryCompiled => this . _getValue ( this . _sliceKey , ID ) ,
159156 isFrozen : this . isFrozen . bind ( this ) ,
160- // Is currently dirty (we may have switched from a slice to a very
161- // different one, thus setting "dirty" on a lot of objects along the
162- // way, all the ones that were modified at one point)
163- // Is your proxy unsynchronized
164- isDirty : ( ID : ProxyUniqID ) : boolean => this . _invalideCache [ ID as number ] ,
165157 // Mark as "modified" in this slice
166158 markDirty : ( ID : ProxyUniqID ) : boolean =>
167159 ( this . _currentReference . invalideCache [ ID as number ] = true ) ,
168160 // I am the proxy, I tell you I synchornized the value
169- markAsLoaded : ( ID : ProxyUniqID ) : boolean => ( this . _invalideCache [ ID as number ] = false ) ,
170161 deleteSliceProxyParent : this . _deleteSliceProxyParent . bind ( this ) ,
171162 addSliceProxyParent : this . _addSliceProxyParent . bind ( this ) ,
172163 linkToMemory : this . _linkToMemory . bind ( this ) ,
@@ -215,14 +206,27 @@ export class Memory {
215206 }
216207 getChangedVersionables ( sliceKey : sliceKey = this . _sliceKey ) : Map < AllowedObject , string [ ] [ ] > {
217208 const pathChanges = new Map < AllowedObject , string [ ] [ ] > ( ) ;
218- const invalideCache = this . _references [ sliceKey ] . invalideCache ;
219- for ( const id in invalideCache ) {
209+ const slice = this . _references [ sliceKey ] . slice ;
210+ for ( const id in slice ) {
211+ const item = slice [ id ] ;
220212 const proxy = this . _proxies [ id ] as LoopObject | LoopArray | LoopSet ;
221213 this . _getRootVersionables ( this . _sliceKey , proxy ) . forEach ( pathToRoot => {
214+ let paths : string [ ] [ ] ;
215+ if (
216+ ( item instanceof MemoryTypeObject || item instanceof MemoryTypeArray ) &&
217+ Object . keys ( item . props ) . length
218+ ) {
219+ paths = [ ] ;
220+ for ( const key in item . props ) {
221+ paths . push ( pathToRoot . path . concat ( [ key ] ) ) ;
222+ }
223+ } else {
224+ paths = [ pathToRoot . path ] ;
225+ }
222226 if ( pathChanges . get ( pathToRoot . proxy ) ) {
223- pathChanges . get ( pathToRoot . proxy ) . push ( pathToRoot . path ) ;
227+ pathChanges . get ( pathToRoot . proxy ) . push ( ... paths ) ;
224228 } else {
225- pathChanges . set ( pathToRoot . proxy , [ pathToRoot . path ] ) ;
229+ pathChanges . set ( pathToRoot . proxy , paths ) ;
226230 }
227231 } ) ;
228232 }
@@ -242,7 +246,7 @@ export class Memory {
242246 if ( ! params . itsme ( proxy ) ) {
243247 return NotVersionableErrorMessage ( ) ;
244248 }
245- if ( params . memory !== this . _memoryVersionable ) {
249+ if ( ! params . memory || params . memory !== this . _memoryVersionable ) {
246250 params . willBeRootDiff = true ;
247251 this . _linkToMemory ( proxy ) ;
248252 }
@@ -304,15 +308,24 @@ export class Memory {
304308 refs . shift ( ) ;
305309 }
306310
311+ const invalideCache = new Set < number > ( ) ;
307312 while ( refs . length ) {
308313 const ref = refs . pop ( ) ;
309314 Object . keys ( ref . invalideCache ) . forEach ( key => {
310315 // It was invalid before, it is still invalid now since it wasn't yet read
311- this . _invalideCache [ key ] = true ;
316+ invalideCache . add ( + key ) ;
312317 } ) ;
313318 }
319+
314320 this . _currentReference = this . _references [ sliceKey ] ;
315321 this . _sliceKey = sliceKey ;
322+
323+ for ( const key of invalideCache ) {
324+ const proxy = this . _proxies [ key ] ;
325+ const params = proxy [ memoryProxyPramsKey ] as VersionableParams ;
326+ params . sync ( ) ;
327+ }
328+
316329 return this ;
317330 }
318331 snapshot ( fromSliceKey : sliceKey , unitSliceKey : sliceKey , newSliceKey : sliceKey ) : void {
@@ -416,9 +429,9 @@ export class Memory {
416429 continue ;
417430 }
418431 this . _getProxyParentedPath ( sliceKey , nodeID ) . forEach ( path => {
419- const nodeID = path . split ( parentedPathSeparator , 1 ) [ 0 ] ;
420- const partPath = path . slice ( nodeID . length + 1 ) ;
421- pathList . push ( [ + nodeID , [ partPath ] . concat ( pathToNode ) ] ) ;
432+ const parentNodeID = path . split ( parentedPathSeparator , 1 ) [ 0 ] ;
433+ const partPath = path . slice ( parentNodeID . length + 1 ) ;
434+ pathList . push ( [ + parentNodeID , [ partPath ] . concat ( pathToNode ) ] ) ;
422435 } ) ;
423436 }
424437 return roots ;
0 commit comments