Skip to content

Commit

Permalink
perf(drag-drop): avoid unnecessary change detection on pointer down e…
Browse files Browse the repository at this point in the history
…vents (#18821)

When the drag&drop was initially implemented it had to trigger change detection immediately once dragging started so that the data bindings get updated correctly. After some time we introduced a threshold for dragging that also triggers its own change detection and makes the initial change detection unnecessary.

Fixes #18726.

(cherry picked from commit 24a7c6d)
  • Loading branch information
crisbeto authored and jelbourn committed Apr 6, 2020
1 parent 7c6be0e commit 2f6e941
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ export class DragRef<T = any> {
this._removeRootElementListeners(this._rootElement);
}

element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
this._ngZone.runOutsideAngular(() => {
element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
});
this._initialTransform = undefined;
this._rootElement = element;
}
Expand Down

0 comments on commit 2f6e941

Please sign in to comment.