浏览代码

add another tiny optimization

Falko Schindler 1 年之前
父节点
当前提交
554c233d2b
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8 3
      nicegui/binding.py

+ 8 - 3
nicegui/binding.py

@@ -71,10 +71,15 @@ def _propagate(source_obj: Any, source_name: str, visited: Optional[Set[Tuple[in
         if (id(target_obj), target_name) in visited:
             continue
 
+        if not _has_attribute(target_obj, target_name):
+            continue
+
         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)
+        if _get_attribute(target_obj, target_name) == target_value:
+            continue
+
+        _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: