#49 : Code cleanup

This commit is contained in:
Vadim
2021-08-08 11:59:39 +03:00
parent e86d1d5e45
commit 257c78b327
3 changed files with 18 additions and 15 deletions

View File

@@ -1,4 +1,7 @@
import { createDispatcher, getIsTouchable } from '../../utils/event'
import {
createDispatcher,
getIsTouchable,
} from '../../utils/event'
import { focusable } from '../focusable'
import { tappable } from '../tappable'

View File

@@ -37,7 +37,7 @@ export function swipeable(node, { thresholdProvider }) {
return swipeDurationMs >= SWIPE_MIN_DURATION_MS && Math.abs(moved) >= SWIPE_MIN_DISTANCE_PX
}
function handleMousedown(event) {
function handleDown(event) {
swipeStartedAt = Date.now()
moved = 0
isTouching = true
@@ -45,11 +45,11 @@ export function swipeable(node, { thresholdProvider }) {
x = coords.x
y = coords.y
dispatch('swipeStart', { x, y })
addMoveEventListener(window, handleMousemove)
addEndEventListener(window, handleMouseup)
addMoveEventListener(window, handleMove)
addEndEventListener(window, handleUp)
}
function handleMousemove(event) {
function handleMove(event) {
if (!isTouching) return
const coords = getCoords(event)
const dx = coords.x - x
@@ -64,14 +64,14 @@ export function swipeable(node, { thresholdProvider }) {
moved += dx
if (Math.abs(moved) > thresholdProvider()) {
dispatch('swipeThresholdReached', { direction: moved > 0 ? PREV : NEXT })
removeEndEventListener(window, handleMouseup)
removeMoveEventListener(window, handleMousemove)
removeEndEventListener(window, handleUp)
removeMoveEventListener(window, handleMove)
}
}
function handleMouseup(event) {
removeEndEventListener(window, handleMouseup)
removeMoveEventListener(window, handleMousemove)
function handleUp(event) {
removeEndEventListener(window, handleUp)
removeMoveEventListener(window, handleMove)
isTouching = false
@@ -83,10 +83,10 @@ export function swipeable(node, { thresholdProvider }) {
dispatch('swipeEnd', { x: coords.x, y: coords.y })
}
addStartEventListener(node, handleMousedown)
addStartEventListener(node, handleDown)
return {
destroy() {
removeStartEventListener(node, handleMousedown)
removeStartEventListener(node, handleDown)
},
}
}

View File

@@ -1,6 +1,6 @@
export const getDistance = (p1, p2) => {
const x = p2.x - p1.x;
const y = p2.y - p1.y;
const xDist = p2.x - p1.x;
const yDist = p2.y - p1.y;
return Math.sqrt((x * x) + (y * y));
return Math.sqrt((xDist * xDist) + (yDist * yDist));
}