Skip to content

Commit fc4d4e5

Browse files
cdvv7788kesselb
authored andcommitted
fix: Replace array with weakmap so lookup is O(1) instead of O(n^2)
Signed-off-by: Cristian <cristianvargasvalencia@gmail.com>
1 parent 9392318 commit fc4d4e5

File tree

1 file changed

+5
-5
lines changed
  • src/directives/drag-and-drop/droppable-mailbox

1 file changed

+5
-5
lines changed

src/directives/drag-and-drop/droppable-mailbox/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
*/
55
import { DroppableMailbox } from './droppable-mailbox.js'
66

7-
let instances = []
7+
const instances = new WeakMap()
88

99
function onBind(el, binding) {
1010
const instance = new DroppableMailbox(el, binding.value)
11-
instances.push(instance)
11+
instances.set(el, instance)
1212
}
1313

1414
function onUpdate(el, binding) {
15-
const instance = instances.find((instance) => instance.el === el)
15+
const instance = instances.get(el)
1616
if (instance) {
1717
instance.options = binding.value
1818
}
1919
}
2020

2121
function onUnbind(el) {
22-
const instance = instances.find((instance) => instance.el === el)
22+
const instance = instances.get(el)
2323
if (instance) {
2424
instance.removeListeners(el)
2525
}
26-
instances = instances.filter((instance) => instance.el !== el)
26+
instances.delete(el)
2727
}
2828

2929
export const DroppableMailboxDirective = {

0 commit comments

Comments
 (0)