Skip to content

Commit 492d22d

Browse files
committed
refactor(touchCoods): extract repeated touches/chagnedTouches lookup
1 parent f02a70b commit 492d22d

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/shared/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export {default as closest} from './closest';
22
export {default as requestNextAnimationFrame} from './requestNextAnimationFrame';
33
export {default as distance} from './distance';
4+
export {default as touchCoords} from './touchCoords';

src/shared/utils/touchCoords/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import touchCoords from './touchCoords';
2+
3+
export default touchCoords;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Returns the first touch event found in touches or changedTouches of a touch events.
3+
* @param {TouchEvent} event a touch event
4+
* @return {Touch} a touch object
5+
*/
6+
export default function touchCoords(event = {}) {
7+
const {touches, changedTouches} = event;
8+
return (touches && touches[0]) || (changedTouches && changedTouches[0]);
9+
}

0 commit comments

Comments
 (0)