Skip to content

Instantly share code, notes, and snippets.

@rowan-m
Created August 27, 2019 09:18
Show Gist options
  • Save rowan-m/a9fe3ca2976e350dbe188494d0ba2c0a to your computer and use it in GitHub Desktop.
Save rowan-m/a9fe3ca2976e350dbe188494d0ba2c0a to your computer and use it in GitHub Desktop.
_onPointerdown(e) {
e.preventDefault();
this._touchX = e.clientX;
this._touchY = e.clientY;
// ✂️ Chop out existing code, extract into new method
this._rotationStart();
this.setPointerCapture(e.pointerId);
this.addEventListener('pointermove', this._onPointermove);
this.addEventListener('pointerup', this._onPointerup);
this.addEventListener('pointercancel', this._onPointerup);
}
_onPointermove(e) {
e.preventDefault();
this._touchX = e.clientX;
this._touchY = e.clientY;
// ✂️ Cut and paste again
this._rotationChange();
}
_onPointerup(e) {
e.preventDefault();
// ✂️ One last time!
this._rotationEnd();
this.releasePointerCapture(e.pointerId);
this.removeEventListener('pointermove', this._onPointermove);
this.removeEventListener('pointerup', this._onPointerup);
this.removeEventListener('pointercancel', this._onPointerup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment