Skip to content

Commit

Permalink
perf(drag-drop): use narrower check for touch events (angular#16082)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored and jelbourn committed Jun 19, 2019
1 parent 4002140 commit b15a7ec
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,10 @@ function removeElement(element: HTMLElement | null) {

/** Determines whether an event is a touch event. */
function isTouchEvent(event: MouseEvent | TouchEvent): event is TouchEvent {
return event.type.startsWith('touch');
// This function is called for every pixel that the user has dragged so we need it to be
// as fast as possible. Since we only bind mouse events and touch events, we can assume
// that if the event's name starts with `t`, it's a touch event.
return event.type[0] === 't';
}

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

0 comments on commit b15a7ec

Please sign in to comment.