desandro / draggabilly

:point_down: Make that shiz draggable
https://draggabilly.desandro.com
MIT License
3.86k stars 387 forks source link

I have some questions about the source code #157

Closed qiangzi7723 closed 6 years ago

qiangzi7723 commented 7 years ago

I am looking at the source code of draggabilly. And I found some functions which bind on prototype are repeated. Such as pointerMove function, I can find there are three pointerMove functions in the source code but only the last one which bind on Draggabilly prototype can be used. So I am confused why so much repeated function in the source code? Because of the update and forget to delete or other? Thank you for your answer.

desandro commented 7 years ago

Thank you for this question! Yes, you are correct. I realize this all a bit confusing. The main reason is that Draggabilly is built upon two other libraries

unipointer -> unidragger -> draggabilly

unipointer provides the base methods for handling the mouse/touch events. _pointerMove is a private method that should not be overwritten. pointerMove is the public method which can be overwritten. Both unidragger and draggabilly overwrite pointerMove. I realize this seems like unecessary code waste, but it allows for a modular pattern. unidragger is reused within Flickity. unipointer is reused in Huebee and tap-listener. Try looking at those repos to see how they overwrite and re-use methods.