@@ -100,7 +100,7 @@ def __enter__(self: _Self) -> _Self:
100
100
def __exit__ (self , * exc : Any ) -> None :
101
101
root_csid = self ._root_life_cycle_state_id
102
102
root_model_state = self ._model_states_by_life_cycle_state_id [root_csid ]
103
- self ._deep_unmount_model_states ([root_model_state ])
103
+ self ._unmount_model_states ([root_model_state ])
104
104
105
105
# delete attributes here to avoid access after exiting context manager
106
106
del self ._event_handlers
@@ -320,7 +320,7 @@ def _render_model_children(
320
320
self ._render_model_children_without_old_state (new_state , raw_children )
321
321
return None
322
322
elif not raw_children :
323
- self ._deep_unmount_model_states (list (old_state .children_by_key .values ()))
323
+ self ._unmount_model_states (list (old_state .children_by_key .values ()))
324
324
return None
325
325
326
326
child_type_key_tuples = list (_process_child_type_and_key (raw_children ))
@@ -335,7 +335,7 @@ def _render_model_children(
335
335
336
336
old_keys = set (old_state .children_by_key ).difference (new_keys )
337
337
if old_keys :
338
- self ._deep_unmount_model_states (
338
+ self ._unmount_model_states (
339
339
[old_state .children_by_key [key ] for key in old_keys ]
340
340
)
341
341
@@ -352,7 +352,7 @@ def _render_model_children(
352
352
)
353
353
else :
354
354
if old_child_state .is_component_state :
355
- self ._shallow_unmount_model_state ( old_child_state )
355
+ self ._unmount_model_states ([ old_child_state ] )
356
356
new_child_state = _update_element_model_state (
357
357
old_child_state ,
358
358
new_state ,
@@ -383,7 +383,7 @@ def _render_model_children(
383
383
else :
384
384
old_child_state = old_state .children_by_key .get (key )
385
385
if old_child_state is not None :
386
- self ._deep_unmount_model_states ([old_child_state ])
386
+ self ._unmount_model_states ([old_child_state ])
387
387
new_children .append (child )
388
388
389
389
def _render_model_children_without_old_state (
@@ -406,21 +406,20 @@ def _render_model_children_without_old_state(
406
406
else :
407
407
new_children .append (child )
408
408
409
- def _deep_unmount_model_states (self , old_states : List [_ModelState ]) -> None :
409
+ def _unmount_model_states (self , old_states : List [_ModelState ]) -> None :
410
410
to_unmount = old_states [::- 1 ] # unmount in reversed order of rendering
411
411
while to_unmount :
412
412
model_state = to_unmount .pop ()
413
- self ._shallow_unmount_model_state (model_state )
414
- to_unmount .extend (model_state .children_by_key .values ())
415
413
416
- def _shallow_unmount_model_state (self , old_state : _ModelState ) -> None :
417
- for target in old_state .targets_by_event .values ():
418
- del self ._event_handlers [target ]
414
+ for target in model_state .targets_by_event .values ():
415
+ del self ._event_handlers [target ]
416
+
417
+ if model_state .is_component_state :
418
+ life_cycle_state = model_state .life_cycle_state
419
+ del self ._model_states_by_life_cycle_state_id [life_cycle_state .id ]
420
+ life_cycle_state .hook .component_will_unmount ()
419
421
420
- if old_state .is_component_state :
421
- life_cycle_state = old_state .life_cycle_state
422
- del self ._model_states_by_life_cycle_state_id [life_cycle_state .id ]
423
- life_cycle_state .hook .component_will_unmount ()
422
+ to_unmount .extend (model_state .children_by_key .values ())
424
423
425
424
def __repr__ (self ) -> str :
426
425
return f"{ type (self ).__name__ } ({ self .root } )"
0 commit comments