Bläddra i källkod

Optimize item registration

Caleb Porzio 1 år sedan
förälder
incheckning
3d15df515f
1 ändrade filer med 20 tillägg och 6 borttagningar
  1. 20 6
      packages/ui/src/list-context.js

+ 20 - 6
packages/ui/src/list-context.js

@@ -16,15 +16,29 @@ export function generateContext(Alpine, multiple, orientation, activateSelectedO
             activateSelectedOrFirst(false)
         }),
 
+        registerItemsQueue: [],
+
         registerItem(key, el, value, disabled) {
-            this.items.push({
-                key, el, value, disabled
-            })
+            // We need to queue up these additions to not slow down the
+            // init process for each row...
+            if (this.registerItemsQueue.length === 0) {
+                queueMicrotask(() => {
+                    if (this.registerItemsQueue.length > 0) {
+                        this.items = this.items.concat(this.registerItemsQueue)
 
-            this.orderedKeys.push(key)
+                        this.registerItemsQueue = []
+
+                        this.reorderKeys()
+                        this.activateSelectedOrFirst()
+                    }
+                })
+            }
+
+            let item = {
+                key, el, value, disabled
+            }
 
-            this.reorderKeys()
-            this.activateSelectedOrFirst()
+            this.registerItemsQueue.push(item)
         },
 
         unregisterKeysQueue: [],