@@ -302,6 +302,55 @@ describe("ArraySchema Tests", () => {
302
302
state . entities . shift ( ) ;
303
303
assertDeepStrictEqualEncodeAll ( state ) ;
304
304
} ) ;
305
+
306
+ xit ( "encodeAll() + with enqueued encode() shifts" , ( ) => {
307
+ class Entity extends Schema {
308
+ @type ( "number" ) thing : number ;
309
+ }
310
+ class State extends Schema {
311
+ @type ( [ Entity ] ) entities : Entity [ ] ;
312
+ }
313
+
314
+ const state = new State ( ) ;
315
+ state . entities = [ ] ;
316
+
317
+ const repopulateEntitiesArray = ( count ) => {
318
+ for ( let i = 0 ; i < count ; i ++ ) {
319
+ const ent = new Entity ( ) ;
320
+ ent . thing = i ;
321
+ state . entities . push ( ent ) ;
322
+ }
323
+ } ;
324
+ repopulateEntitiesArray ( 35 ) ;
325
+
326
+ function mutateAllAndShift ( count : number = 6 ) {
327
+ for ( let i = 0 ; i < count ; i ++ ) {
328
+ state . entities . forEach ( ( entity ) => entity . thing ++ ) ;
329
+ state . entities . shift ( ) ;
330
+ }
331
+ }
332
+
333
+ const decoded1 = createInstanceFromReflection ( state ) ;
334
+ decoded1 . decode ( state . encodeAll ( ) ) ;
335
+ mutateAllAndShift ( 6 ) ;
336
+ decoded1 . decode ( state . encode ( ) ) ;
337
+ mutateAllAndShift ( 6 ) ;
338
+ decoded1 . decode ( state . encode ( ) ) ;
339
+
340
+ mutateAllAndShift ( 9 ) ;
341
+
342
+ const decoded2 = createInstanceFromReflection ( state ) ;
343
+ console . log ( "\n\n\n\nDECODE FULL!" ) ;
344
+ decoded2 . decode ( state . encodeAll ( ) ) ;
345
+ console . log ( "FULL REFS:" , getDecoder ( decoded2 ) . root . refs . size , '=>' , Array . from ( getDecoder ( decoded2 ) . root . refs . keys ( ) ) ) ;
346
+ mutateAllAndShift ( 3 ) ;
347
+ decoded2 . decode ( state . encode ( ) ) ;
348
+ console . log ( "PATCH REFS:" , getDecoder ( decoded2 ) . root . refs . size , '=>' , Array . from ( getDecoder ( decoded2 ) . root . refs . keys ( ) ) ) ;
349
+ mutateAllAndShift ( 6 ) ;
350
+ decoded2 . decode ( state . encode ( ) ) ;
351
+
352
+ assertDeepStrictEqualEncodeAll ( state ) ;
353
+ } ) ;
305
354
} ) ;
306
355
307
356
it ( "should allow mutating primitive value by index" , ( ) => {
0 commit comments