Kaynağa Gözat

code review

Falko Schindler 1 yıl önce
ebeveyn
işleme
10da47c596
1 değiştirilmiş dosya ile 10 ekleme ve 12 silme
  1. 10 12
      nicegui/binding.py

+ 10 - 12
nicegui/binding.py

@@ -55,28 +55,26 @@ def _refresh_step() -> None:
         log.warning(f'binding propagation for {len(active_links)} active links took {time.time() - t:.3f} s')
 
 
-def _propagate(source_obj: Any, source_name: str, visited: Optional[Set[int]] = None) -> None:
+def _propagate(source_obj: Any, source_name: str, visited: Optional[Set[Tuple[int, str]]] = None) -> None:
     if visited is None:
         visited = set()
-
     source_obj_id = id(source_obj)
     if source_obj_id in visited:
         return
-    visited.add(source_obj_id)
+    visited.add((source_obj_id, source_name))
 
-    source_attr_exists = _has_attribute(source_obj, source_name)
-    source_value = _get_attribute(source_obj, source_name) if source_attr_exists else None
+    if not _has_attribute(source_obj, source_name):
+        return
+    source_value = _get_attribute(source_obj, source_name)
 
     for _, target_obj, target_name, transform in bindings.get((source_obj_id, source_name), []):
-        target_obj_id = id(target_obj)
-        if target_obj_id in visited:
+        if (id(target_obj), target_name) in visited:
             continue
 
-        if source_attr_exists:
-            target_value = transform(source_value)
-            if not _has_attribute(target_obj, target_name) or _get_attribute(target_obj, target_name) != target_value:
-                _set_attribute(target_obj, target_name, target_value)
-                _propagate(target_obj, target_name, visited)
+        target_value = transform(source_value)
+        if not _has_attribute(target_obj, target_name) or _get_attribute(target_obj, target_name) != target_value:
+            _set_attribute(target_obj, target_name, target_value)
+            _propagate(target_obj, target_name, visited)
 
 
 def bind_to(self_obj: Any, self_name: str, other_obj: Any, other_name: str, forward: Callable[[Any], Any]) -> None: