瀏覽代碼

Fix and optimize the unregisterItem method further

Caleb Porzio 1 年之前
父節點
當前提交
235d4b4972
共有 1 個文件被更改,包括 3 次插入10 次删除
  1. 3 10
      packages/ui/src/list-context.js

+ 3 - 10
packages/ui/src/list-context.js

@@ -38,18 +38,11 @@ export function generateContext(Alpine, multiple, orientation, activateSelectedO
             if (this.unregisterKeysQueue.length === 0) {
                 queueMicrotask(() => {
                     if (this.unregisterKeysQueue.length > 0) {
-                        for (let i = 0; i < this.unregisterKeysQueue.length; i++) {
-                            let key = this.unregisterKeysQueue[i]
-
-                            let j = this.items.findIndex((j) => j.key === key)
-                            if (j !== -1) this.items.splice(j, 1)
-
-                            j = this.orderedKeys.indexOf(key)
-                            if (j !== -1) this.orderedKeys.splice(j, 1)
-                        }
-
                         this.unregisterKeysQueue = []
 
+                        this.items = this.items.filter(i => i.key === key)
+                        this.orderedKeys = this.orderedKeys.filter(i => i === key)
+
                         this.reorderKeys()
                         this.activateSelectedOrFirst()
                     }