Giter Club home page Giter Club logo

Comments (3)

bcherny avatar bcherny commented on June 20, 2024

Hi @swang! Can you talk a little about the motivation for this? Why would you want a single event listener instead of one for each draggable?

from draggable.

swang avatar swang commented on June 20, 2024

My use case would be multiple draggable elements sitting under the same container. E.g. Being able to move pieces on a chess board.

Generally speaking delegating events to the container (a parent element) should use less memory than assigning events to each individual element. I'm assuming it's also quicker to instantiate that one event rather than multiple events. I've tried this w/ click events, but may also have to test mousemove events to see if there is still the same improvement.

So if I have a page that has several different chessboards that show different scenarios. Instead of having to create an event for every piece of every board. I can just define one listen event delegator to handle it.

Doing this also allows me to add/remove draggable elements without having to redefine a new draggable instance each time an element is created since the event delegate handles it.

from draggable.

bcherny avatar bcherny commented on June 20, 2024

Generally speaking delegating events to the container (a parent element) should use less memory than assigning events to each individual element.

This is not really the case with modern browsers, and hasn't been for some time. If you run a benchmark, you'll see there is no difference between the delegated and non-delegated versions.

I'm assuming it's also quicker to instantiate that one event rather than multiple events

Maybe by, like, nanoseconds? Have you tried profiling this to get some real numbers?

This doesn't seem like a good use case to me. If you can produce a benchmark that shows an improvement with delegation, I'd be more than happy to support this.

from draggable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.