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 18, 2024
1 parent 173e73e commit 8d1dc5e
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 @@ -2129,7 +2129,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 8d1dc5e

Please sign in to comment.