neodrag icon indicating copy to clipboard operation
neodrag copied to clipboard

Handle all events with eventListener object handle event method

Open JonathonRP opened this issue 5 months ago • 7 comments

It would be nice if 'listen' util method could handle events similar to article solution - https://webreflection.medium.com/dom-handleevent-a-cross-platform-standard-since-year-2000-5bf17287fd38.

JonathonRP avatar Jul 18 '25 22:07 JonathonRP

Not sure what is the merit of this solution here. The library already implements event delegation and has been tested for memory usage pre event delegation and post delegation

PuruVJ avatar Jul 19 '25 04:07 PuruVJ

I believe the crutch Memory usage per event vs only a single allocation for every event?

JonathonRP avatar Jul 19 '25 04:07 JonathonRP

Not sure what you mean? Have you seen the setup listeners function in core/index.ts? That is event delegation and it works well

PuruVJ avatar Jul 19 '25 05:07 PuruVJ

All I see in packages/core/src/index.ts is a listen that just calls add listener for both main branch and new-api branch

JonathonRP avatar Jul 19 '25 05:07 JonathonRP

Please study the new-api branch’s core/index.ts thoroughly. This does not need the handleEvent

On Sat, 19 Jul 2025 at 10:42 AM, Jonathon Reese Perry < @.***> wrote:

JonathonRP left a comment (PuruVJ/neodrag#231) https://github.com/PuruVJ/neodrag/issues/231#issuecomment-3091843527

All I see in packages/core/src/index.ts is a listen that just calls add listener for both main branch and new-api branch

— Reply to this email directly, view it on GitHub https://github.com/PuruVJ/neodrag/issues/231#issuecomment-3091843527, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALMH4F6YVWUC5P4464YSJKT3JHHVPAVCNFSM6AAAAACB3ZAVEGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAOJRHA2DGNJSG4 . You are receiving this because you commented.Message ID: @.***>

PuruVJ avatar Jul 19 '25 05:07 PuruVJ

Still looks like you are initializing 4 listeners, that hold single function call through binding to self functions for handling, when you could just have listen(el, this), and example implementation

handleEvent(type) {
this[`on${type}`].call().bind(this);
}

Unless I am missing something.

JonathonRP avatar Jul 19 '25 05:07 JonathonRP

I'm not sure I get the advantages of this in the context. Please raise a PR with the testes changes and we can discuss further there

PuruVJ avatar Jul 19 '25 08:07 PuruVJ