Skip to content

Commit f45923d

Browse files
committed
perf(drag-drop): use narrower check for touch events
We use the `isTouchEvent` any time we need to normalize something between touch and mouse events which happens for every pixel that the user has dragged. These changes switch to using direct comparison, rather than `startsWith`, which should be slightly faster since there's a narrow set of touch event types.
1 parent 0908be7 commit f45923d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cdk/drag-drop/drag-ref.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,9 @@ function removeElement(element: HTMLElement | null) {
11031103

11041104
/** Determines whether an event is a touch event. */
11051105
function isTouchEvent(event: MouseEvent | TouchEvent): event is TouchEvent {
1106-
return event.type.startsWith('touch');
1106+
const type = event.type;
1107+
return type === 'touchmove' || type === 'touchstart' || type === 'touchend' ||
1108+
type === 'touchcancel';
11071109
}
11081110

11091111
/** Gets the element into which the drag preview should be inserted. */

0 commit comments

Comments
 (0)