Skip to content

Commit

Permalink
Change event handlers from anonymous functions so they can be properl…
Browse files Browse the repository at this point in the history
…y removed
  • Loading branch information
Dan Rittman authored and Dan Rittman committed May 24, 2023
1 parent 56e581f commit 96887b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Joystick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
dragging: true
});

window.addEventListener(InteractionEvents.PointerUp, event => this._pointerUp(event));
window.addEventListener(InteractionEvents.PointerMove, event => this._pointerMove(event));
window.addEventListener(InteractionEvents.PointerUp, this._pointerUp);
window.addEventListener(InteractionEvents.PointerMove, this._pointerMove);
this._pointerId = e.pointerId
//@ts-ignore
this._stickRef.current.setPointerCapture(e.pointerId);
Expand Down Expand Up @@ -244,7 +244,7 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
* @param event
* @private
*/
private _pointerMove(event: PointerEvent) {
private _pointerMove = (event: PointerEvent) => {
event.preventDefault()
if (this.state.dragging) {
if(!this.props.followCursor && event.pointerId !== this._pointerId) return;
Expand Down Expand Up @@ -286,7 +286,7 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
* Handle pointer up and de-register listen events
* @private
*/
private _pointerUp(event: PointerEvent) {
private _pointerUp = (event: PointerEvent) => {
if(event.pointerId !== this._pointerId) return;
const stateUpdate = {
dragging: false,
Expand All @@ -300,8 +300,8 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
}
});

window.removeEventListener(InteractionEvents.PointerUp, event => this._pointerUp(event));
window.removeEventListener(InteractionEvents.PointerMove, event => this._pointerMove(event));
window.removeEventListener(InteractionEvents.PointerUp, this._pointerUp));
window.removeEventListener(InteractionEvents.PointerMove, this._pointerMove);
this._pointerId = null;
if (this.props.stop) {
this.props.stop({
Expand Down

0 comments on commit 96887b7

Please sign in to comment.