#49 : Code cleanup
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import { createDispatcher, getIsTouchable } from '../../utils/event'
|
import {
|
||||||
|
createDispatcher,
|
||||||
|
getIsTouchable,
|
||||||
|
} from '../../utils/event'
|
||||||
|
|
||||||
import { focusable } from '../focusable'
|
import { focusable } from '../focusable'
|
||||||
import { tappable } from '../tappable'
|
import { tappable } from '../tappable'
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export function swipeable(node, { thresholdProvider }) {
|
|||||||
return swipeDurationMs >= SWIPE_MIN_DURATION_MS && Math.abs(moved) >= SWIPE_MIN_DISTANCE_PX
|
return swipeDurationMs >= SWIPE_MIN_DURATION_MS && Math.abs(moved) >= SWIPE_MIN_DISTANCE_PX
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMousedown(event) {
|
function handleDown(event) {
|
||||||
swipeStartedAt = Date.now()
|
swipeStartedAt = Date.now()
|
||||||
moved = 0
|
moved = 0
|
||||||
isTouching = true
|
isTouching = true
|
||||||
@@ -45,11 +45,11 @@ export function swipeable(node, { thresholdProvider }) {
|
|||||||
x = coords.x
|
x = coords.x
|
||||||
y = coords.y
|
y = coords.y
|
||||||
dispatch('swipeStart', { x, y })
|
dispatch('swipeStart', { x, y })
|
||||||
addMoveEventListener(window, handleMousemove)
|
addMoveEventListener(window, handleMove)
|
||||||
addEndEventListener(window, handleMouseup)
|
addEndEventListener(window, handleUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMousemove(event) {
|
function handleMove(event) {
|
||||||
if (!isTouching) return
|
if (!isTouching) return
|
||||||
const coords = getCoords(event)
|
const coords = getCoords(event)
|
||||||
const dx = coords.x - x
|
const dx = coords.x - x
|
||||||
@@ -64,14 +64,14 @@ export function swipeable(node, { thresholdProvider }) {
|
|||||||
moved += dx
|
moved += dx
|
||||||
if (Math.abs(moved) > thresholdProvider()) {
|
if (Math.abs(moved) > thresholdProvider()) {
|
||||||
dispatch('swipeThresholdReached', { direction: moved > 0 ? PREV : NEXT })
|
dispatch('swipeThresholdReached', { direction: moved > 0 ? PREV : NEXT })
|
||||||
removeEndEventListener(window, handleMouseup)
|
removeEndEventListener(window, handleUp)
|
||||||
removeMoveEventListener(window, handleMousemove)
|
removeMoveEventListener(window, handleMove)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseup(event) {
|
function handleUp(event) {
|
||||||
removeEndEventListener(window, handleMouseup)
|
removeEndEventListener(window, handleUp)
|
||||||
removeMoveEventListener(window, handleMousemove)
|
removeMoveEventListener(window, handleMove)
|
||||||
|
|
||||||
isTouching = false
|
isTouching = false
|
||||||
|
|
||||||
@@ -83,10 +83,10 @@ export function swipeable(node, { thresholdProvider }) {
|
|||||||
dispatch('swipeEnd', { x: coords.x, y: coords.y })
|
dispatch('swipeEnd', { x: coords.x, y: coords.y })
|
||||||
}
|
}
|
||||||
|
|
||||||
addStartEventListener(node, handleMousedown)
|
addStartEventListener(node, handleDown)
|
||||||
return {
|
return {
|
||||||
destroy() {
|
destroy() {
|
||||||
removeStartEventListener(node, handleMousedown)
|
removeStartEventListener(node, handleDown)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export const getDistance = (p1, p2) => {
|
export const getDistance = (p1, p2) => {
|
||||||
const x = p2.x - p1.x;
|
const xDist = p2.x - p1.x;
|
||||||
const y = p2.y - p1.y;
|
const yDist = p2.y - p1.y;
|
||||||
|
|
||||||
return Math.sqrt((x * x) + (y * y));
|
return Math.sqrt((xDist * xDist) + (yDist * yDist));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user