소스 검색

Bulk vue updates on update (#4235)

I noticed that adding or changing a large number of elements, especially
inside an SVG tag, takes very long.

This changes the update handler to first load all dependencies in
parallel and then update the elements.
Niklas Neugebauer 4 달 전
부모
커밋
4990c7228b
1개의 변경된 파일6개의 추가작업 그리고 3개의 파일을 삭제
  1. 6 3
      nicegui/static/nicegui.js

+ 6 - 3
nicegui/static/nicegui.js

@@ -376,14 +376,17 @@ function createApp(elements, options) {
           document.getElementById("popup").ariaHidden = false;
         },
         update: async (msg) => {
+          const loadPromises = Object.entries(msg)
+            .filter(([_, element]) => element && (element.component || element.libraries))
+            .map(([_, element]) => loadDependencies(element, options.prefix, options.version));
+
+          await Promise.all(loadPromises);
+
           for (const [id, element] of Object.entries(msg)) {
             if (element === null) {
               delete this.elements[id];
               continue;
             }
-            if (element.component || element.libraries) {
-              await loadDependencies(element, options.prefix, options.version);
-            }
             this.elements[id] = element;
             replaceUndefinedAttributes(this.elements, id);
           }