@@ -323,6 +323,39 @@ describe("Type: MapSchema", () => {
323
323
assertDeepStrictEqualEncodeAll ( state ) ;
324
324
} ) ;
325
325
326
+ it ( "removing item with children should remove children as well" , ( ) => {
327
+ class Item extends Schema {
328
+ @type ( "string" ) name : string ;
329
+ }
330
+ class Entity extends Schema {
331
+ @type ( "string" ) name : string ;
332
+ @type ( [ Item ] ) items = new ArraySchema < Item > ( ) ;
333
+ }
334
+ class State extends Schema {
335
+ @type ( { map : Entity } ) entities = new MapSchema < Entity > ( ) ;
336
+ }
337
+
338
+ const state = new State ( ) ;
339
+ for ( let i = 0 ; i < 5 ; i ++ ) {
340
+ state . entities . set ( "e" + i , new Entity ( ) . assign ( {
341
+ name : "Entity " + i ,
342
+ items : [
343
+ new Item ( ) . assign ( { name : "Item A" } ) ,
344
+ new Item ( ) . assign ( { name : "Item B" } ) ,
345
+ ]
346
+ } ) ) ;
347
+ }
348
+
349
+ const decodedState = createInstanceFromReflection ( state ) ;
350
+ decodedState . decode ( state . encode ( ) ) ;
351
+
352
+ assertRefIdCounts ( state , decodedState ) ;
353
+
354
+ state . entities . delete ( "e3" ) ;
355
+ decodedState . decode ( state . encode ( ) ) ;
356
+ assertRefIdCounts ( state , decodedState ) ;
357
+ } ) ;
358
+
326
359
it ( "should allow map of primitive types" , ( ) => {
327
360
class Player extends Schema {
328
361
@type ( { map : "number" } ) mapOfNumbers = new MapSchema < number > ( ) ;
0 commit comments