PuruVJ / neodrag

One Draggable to rule them all 💍
https://neodrag.dev
MIT License
1.59k stars 48 forks source link

Why does `addEventListener` attach to not `node` but `window`? #170

Open studioTeaTwo opened 1 week ago

studioTeaTwo commented 1 week ago

I am going to use it in the case of multiple nodes and the repetition of node.append/node.remove. This can cause problems because removeEventListener can not properly find the corresponding Listeners, leaving Listeners referencing the removed Node.

Current core code is:

    const listen = addEventListener;

    listen('pointerdown', drag_start, false);
    listen('pointerup', drag_end, false);
    listen('pointermove', drag, false);

I think it's better:

    const listen = node.addEventListener;

    listen('pointerdown', drag_start, false);
    listen('pointerup', drag_end, false);
    listen('pointermove', drag, false);