Skip to content

Commit d4579e6

Browse files
crisbetojelbourn
authored andcommitted
refactor(overlay): remove explicit subscription count (#15455)
Uses the observer count from the `Subject` itself, rather than counting it manually. Relates to #15441.
1 parent b1c10d1 commit d4579e6

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
validateHorizontalPosition,
1717
validateVerticalPosition,
1818
} from './connected-position';
19-
import {Observable, Subscription, Subject, Observer} from 'rxjs';
19+
import {Observable, Subscription, Subject} from 'rxjs';
2020
import {OverlayReference} from '../overlay-reference';
2121
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
2222
import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
@@ -115,9 +115,6 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
115115
/** Selector to be used when finding the elements on which to set the transform origin. */
116116
private _transformOriginSelector: string;
117117

118-
/** Amount of subscribers to the `positionChanges` stream. */
119-
private _positionChangeSubscriptions = 0;
120-
121118
/** Keeps track of the CSS classes that the position strategy has applied on the overlay panel. */
122119
private _appliedPanelClasses: string[] = [];
123120

@@ -126,18 +123,10 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
126123

127124
/** Observable sequence of position changes. */
128125
positionChanges: Observable<ConnectedOverlayPositionChange> =
129-
new Observable((observer: Observer<ConnectedOverlayPositionChange>) => {
130-
const subscription = this._positionChanges.subscribe(observer);
131-
this._positionChangeSubscriptions++;
132-
133-
return () => {
134-
subscription.unsubscribe();
135-
this._positionChangeSubscriptions--;
136-
};
137-
});
126+
this._positionChanges.asObservable();
138127

139128
/** Ordered list of preferred positions, from most to least desirable. */
140-
get positions() {
129+
get positions(): ConnectionPositionPair[] {
141130
return this._preferredPositions;
142131
}
143132

@@ -667,7 +656,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
667656
// Notify that the position has been changed along with its change properties.
668657
// We only emit if we've got any subscriptions, because the scroll visibility
669658
// calculcations can be somewhat expensive.
670-
if (this._positionChangeSubscriptions > 0) {
659+
if (this._positionChanges.observers.length) {
671660
const scrollableViewProperties = this._getScrollVisibility();
672661
const changeEvent = new ConnectedOverlayPositionChange(position, scrollableViewProperties);
673662
this._positionChanges.next(changeEvent);

0 commit comments

Comments
 (0)