-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unregister element #2
Comments
Ah yes, I'd forgotten about this. Will add an API to detach the event listener. |
Hi @knadh , not removing elements from |
- Fully refactor the event handling approach and rewite the script to just have 3 global listeners instead of the earlier approach of having 2 events per item. - Maintain items in a `WeakMap()` instead of a maintaing states in a function per object. - Simplify logic for readability. - Add `remove()` to allow the drag/move events on an object to be unregistered. The new approach should is significantly more memory efficient. Closes #2.
@obrejla I ended up rewriting the whole script to be more memory efficient. It also now lets you unregister elements. You can find it here: #13 Example: const d = dragmove(document.querySelector("#test"), document.querySelector("#test .handle"), onStart, onEnd);
d.remove(); Even if you don't remove, the new version keeps track of DOM objects using a There are no breaking changes. Please give the branch a shot and I'll merge. |
If an element no longer needs to be dragged, could it be "unregistered" and removed from the callbacks array? This would help save memory especially in single page apps where several views could potentially be shown or rerendered.
The text was updated successfully, but these errors were encountered: