Comments (3)
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.
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.
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)
- Error with webpack when importing ES6 style HOT 8
- Handle element HOT 2
- Error occured while using the lib for server side rendering HOT 2
- Calling Draggable(element) raises an Error
- Limit by element doesn't work (Vue.js) HOT 3
- Draggable iframe HOT 1
- Textarea HOT 2
- onDrag "x" and "y" always are NaN HOT 2
- contenteditable="true" not working HOT 2
- How to set default position for element? HOT 2
- How to use as drag and drop HOT 1
- how to using filterTarget prop HOT 2
- destroy ? HOT 1
- how can I save final draged draggable to svg ? HOT 1
- require syntax
- How to drag a sub-elements from draggable section
- Prevent click when dragging ?
- Content clicks don't register on mobile devices HOT 1
- "set" method to set the same location. The first set succeeds and the next set fails.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draggable.