Skip to content

Commit

Permalink
Small refactoring of the getClientCoords function
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet committed Jun 30, 2022
1 parent e453f0e commit e9c2c04
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/@classes/abstract/IsometricDraggable/IsometricDraggable.ts
Expand Up @@ -41,17 +41,20 @@ const _dragStoreDefault = {
};

const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => 'clientX' in event;
const getClientCoords = (event: MouseEvent | TouchEvent): ClientCoords => {
if (isMouseEvent(event)) {
const getClientCoords = (event: MouseEvent | TouchEvent | ClientCoords): ClientCoords => {
if (event instanceof Event) {
if (isMouseEvent(event)) {
return {
clientX: event.clientX,
clientY: event.clientY
};
}
return {
clientX: event.clientX,
clientY: event.clientY
clientX: event.touches[0].clientX,
clientY: event.touches[0].clientY
};
}
return {
clientX: event.touches[0].clientX,
clientY: event.touches[0].clientY
};
return event;
};

export abstract class IsometricDraggable extends IsometricElement {
Expand Down Expand Up @@ -160,9 +163,7 @@ export abstract class IsometricDraggable extends IsometricElement {
event.preventDefault();
}

const { clientX, clientY } = event instanceof Event
? getClientCoords(event)
: event;
const { clientX, clientY } = getClientCoords(event);
const diffX = clientX - this._dragStore.x;
const diffY = clientY - this._dragStore.y;
if (this._drag === PlaneView.TOP) {
Expand Down

0 comments on commit e9c2c04

Please sign in to comment.