Skip to content

Commit f7c53d6

Browse files
vitaliy-bobrovjelbourn
authored andcommitted
refactor(drag-drop): remove manual observers count (#15441)
1 parent 941a0d9 commit f7c53d6

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ViewportRuler} from '@angular/cdk/scrolling';
1111
import {Direction} from '@angular/cdk/bidi';
1212
import {normalizePassiveListenerOptions} from '@angular/cdk/platform';
1313
import {coerceBooleanProperty, coerceElement} from '@angular/cdk/coercion';
14-
import {Subscription, Subject, Observable, Observer} from 'rxjs';
14+
import {Subscription, Subject, Observable} from 'rxjs';
1515
import {DropListRefInternal as DropListRef} from './drop-list-ref';
1616
import {DragDropRegistry} from './drag-drop-registry';
1717
import {extendStyles, toggleNativeDragInteractions} from './drag-styling';
@@ -130,12 +130,6 @@ export class DragRef<T = any> {
130130
delta: {x: -1 | 0 | 1, y: -1 | 0 | 1};
131131
}>();
132132

133-
/**
134-
* Amount of subscriptions to the move event. Used to avoid
135-
* hitting the zone if the consumer didn't subscribe to it.
136-
*/
137-
private _moveEventSubscriptions = 0;
138-
139133
/** Keeps track of the direction in which the user is dragging along each axis. */
140134
private _pointerDirectionDelta: {x: -1 | 0 | 1, y: -1 | 0 | 1};
141135

@@ -260,15 +254,7 @@ export class DragRef<T = any> {
260254
pointerPosition: {x: number, y: number};
261255
event: MouseEvent | TouchEvent;
262256
delta: {x: -1 | 0 | 1, y: -1 | 0 | 1};
263-
}> = new Observable((observer: Observer<any>) => {
264-
const subscription = this._moveEvents.subscribe(observer);
265-
this._moveEventSubscriptions++;
266-
267-
return () => {
268-
subscription.unsubscribe();
269-
this._moveEventSubscriptions--;
270-
};
271-
});
257+
}> = this._moveEvents.asObservable();
272258

273259
/** Arbitrary data that can be attached to the drag item. */
274260
data: T;
@@ -563,7 +549,7 @@ export class DragRef<T = any> {
563549
// Since this event gets fired for every pixel while dragging, we only
564550
// want to fire it if the consumer opted into it. Also we have to
565551
// re-enter the zone because we run all of the events on the outside.
566-
if (this._moveEventSubscriptions > 0) {
552+
if (this._moveEvents.observers.length) {
567553
this._ngZone.run(() => {
568554
this._moveEvents.next({
569555
source: this,

0 commit comments

Comments
 (0)