@@ -361,7 +361,7 @@ def _render_model_children(
361
361
[old_state .children_by_key [key ] for key in old_keys ]
362
362
)
363
363
364
- new_children = new_state .model .current ["children" ] = []
364
+ new_state .model .current ["children" ] = []
365
365
for index , (child , child_type , key ) in enumerate (child_type_key_tuples ):
366
366
old_child_state = old_state .children_by_key .get (key )
367
367
if child_type is _DICT_TYPE :
@@ -388,7 +388,7 @@ def _render_model_children(
388
388
index ,
389
389
)
390
390
self ._render_model (exit_stack , old_child_state , new_child_state , child )
391
- new_children . append (new_child_state .model .current )
391
+ new_state . append_child (new_child_state .model .current )
392
392
new_state .children_by_key [key ] = new_child_state
393
393
elif child_type is _COMPONENT_TYPE :
394
394
child = cast (ComponentType , child )
@@ -428,7 +428,7 @@ def _render_model_children(
428
428
old_child_state = old_state .children_by_key .get (key )
429
429
if old_child_state is not None :
430
430
self ._unmount_model_states ([old_child_state ])
431
- new_children . append (child )
431
+ new_state . append_child (child )
432
432
433
433
def _render_model_children_without_old_state (
434
434
self ,
@@ -446,20 +446,20 @@ def _render_model_children_without_old_state(
446
446
f"Duplicate keys { duplicate_keys } at { new_state .patch_path or '/' !r} "
447
447
)
448
448
449
- new_children = new_state .model .current ["children" ] = []
449
+ new_state .model .current ["children" ] = []
450
450
for index , (child , child_type , key ) in enumerate (child_type_key_tuples ):
451
451
if child_type is _DICT_TYPE :
452
452
child_state = _make_element_model_state (new_state , index , key )
453
453
self ._render_model (exit_stack , None , child_state , child )
454
- new_children . append (child_state .model .current )
454
+ new_state . append_child (child_state .model .current )
455
455
new_state .children_by_key [key ] = child_state
456
456
elif child_type is _COMPONENT_TYPE :
457
457
child_state = _make_component_model_state (
458
458
new_state , index , key , child , self ._rendering_queue .put
459
459
)
460
460
self ._render_component (exit_stack , None , child_state , child )
461
461
else :
462
- new_children . append (child )
462
+ new_state . append_child (child )
463
463
464
464
def _unmount_model_states (self , old_states : List [_ModelState ]) -> None :
465
465
to_unmount = old_states [::- 1 ] # unmount in reversed order of rendering
@@ -661,6 +661,9 @@ def parent(self) -> _ModelState:
661
661
assert parent is not None , "detached model state"
662
662
return parent
663
663
664
+ def append_child (self , child : Any ) -> None :
665
+ self .model .current ["children" ].append (child )
666
+
664
667
def __repr__ (self ) -> str : # pragma: no cover
665
668
return f"ModelState({ {s : getattr (self , s , None ) for s in self .__slots__ } } )"
666
669
0 commit comments