Skip to content

Commit

Permalink
feat: check for key mutation when removing children
Browse files Browse the repository at this point in the history
  • Loading branch information
iisakkirotko committed Apr 17, 2024
1 parent e49f97c commit 9c92ae2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions reacton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,12 @@ def _remove_element(self, el: Element, default_key: str, parent_key):
new_parent_key = join_key(parent_key, key)
self._remove_element(self.context.root_element, "/", parent_key=new_parent_key)
finally:
def _check_key_mutation(child_context: ComponentContext):
for key, el in child_context.elements.items():
if key != el._key:
raise RuntimeError(f"Key mismatch: {key} != {el._key}. Did you mutate a key?")
try:
_check_key_mutation(child_context)
assert not child_context.elements, f"left over elements {child_context.elements}"
assert not child_context.element_to_widget, f"left over element_to_widget {child_context.element_to_widget}"
assert not child_context.widgets, f"left over widgets {child_context.widgets}"
Expand Down

0 comments on commit 9c92ae2

Please sign in to comment.