Skip to content

Commit 7ea505b

Browse files
authored
refactor: replace asObservable usages (#20165)
As discussed, replaces usages of the `asObservable` with a cast to `Observable` since the method is a little pointless, because people can easily get around it if they really want to. Also cleans up a few getters that were returning observables.
1 parent 6569041 commit 7ea505b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+84
-94
lines changed

src/cdk-experimental/column-resize/column-resize-notifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ColumnResizeNotifierSource {
5656
@Injectable()
5757
export class ColumnResizeNotifier {
5858
/** Emits whenever a column is resized. */
59-
readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted.asObservable();
59+
readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted;
6060

6161
constructor(private readonly _source: ColumnResizeNotifierSource) {}
6262

src/cdk-experimental/dialog/dialog-ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ export class DialogRef<T, R = any> {
133133

134134
/** Gets an observable that emits when dialog begins opening. */
135135
beforeOpened(): Observable<void> {
136-
return this._containerInstance._beforeEnter.asObservable();
136+
return this._containerInstance._beforeEnter;
137137
}
138138

139139
/** Gets an observable that emits when dialog is finished opening. */
140140
afterOpened(): Observable<void> {
141-
return this._containerInstance._afterEnter.asObservable();
141+
return this._containerInstance._afterEnter;
142142
}
143143

144144
/** Gets an observable that emits when dialog begins closing. */

src/cdk-experimental/popover-edit/edit-ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import {EditEventDispatcher} from './edit-event-dispatcher';
2121
export class EditRef<FormValue> implements OnDestroy {
2222
/** Emits the final value of this edit instance before closing. */
2323
private readonly _finalValueSubject = new Subject<FormValue>();
24-
readonly finalValue: Observable<FormValue> = this._finalValueSubject.asObservable();
24+
readonly finalValue: Observable<FormValue> = this._finalValueSubject;
2525

2626
/** Emits when the user tabs out of this edit lens before closing. */
2727
private readonly _blurredSubject = new Subject<void>();
28-
readonly blurred: Observable<void> = this._blurredSubject.asObservable();
28+
readonly blurred: Observable<void> = this._blurredSubject;
2929

3030
/** The value to set the form back to on revert. */
3131
private _revertFormValue: FormValue;

src/cdk-experimental/popover-edit/focus-escape-notifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class FocusEscapeNotifier extends FocusTrap {
4646
}
4747

4848
escapes(): Observable<FocusEscapeNotifierDirection> {
49-
return this._escapeSubject.asObservable();
49+
return this._escapeSubject;
5050
}
5151
}
5252

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class ElementDataSource extends DataSource<PeriodicElement> {
253253

254254
/** Connect function called by the table to retrieve one stream containing the data to render. */
255255
connect() {
256-
return this.data.asObservable();
256+
return this.data;
257257
}
258258

259259
disconnect() {}

src/cdk/a11y/focus-monitor/focus-monitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class FocusMonitor implements OnDestroy {
247247
cachedInfo.checkChildren = true;
248248
}
249249

250-
return cachedInfo.subject.asObservable();
250+
return cachedInfo.subject;
251251
}
252252

253253
// Create monitored element info.
@@ -259,7 +259,7 @@ export class FocusMonitor implements OnDestroy {
259259
this._elementInfo.set(nativeElement, info);
260260
this._registerGlobalListeners(info);
261261

262-
return info.subject.asObservable();
262+
return info.subject;
263263
}
264264

265265
/**

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class FocusTrap {
341341
if (this._ngZone.isStable) {
342342
fn();
343343
} else {
344-
this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(fn);
344+
this._ngZone.onStable.pipe(take(1)).subscribe(fn);
345345
}
346346
}
347347
}

src/cdk/drag-drop/directives/drag.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ describe('CdkDrag', () => {
24072407
const itemInstance = fixture.componentInstance.dragItems.toArray()[1];
24082408
const item = itemInstance.element.nativeElement;
24092409
const spy = jasmine.createSpy('dropped spy');
2410-
const subscription = itemInstance.dropped.asObservable().subscribe(spy);
2410+
const subscription = itemInstance.dropped.subscribe(spy);
24112411

24122412
// Do an initial drag and drop sequence.
24132413
dragElementViaMouse(fixture, item, 50, 50);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
251251
// element to be in the proper place in the DOM. This is mostly relevant
252252
// for draggable elements inside portals since they get stamped out in
253253
// their original DOM position and then they get transferred to the portal.
254-
this._ngZone.onStable.asObservable()
254+
this._ngZone.onStable
255255
.pipe(take(1), takeUntil(this._destroyed))
256256
.subscribe(() => {
257257
this._updateRootElement();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class DragRef<T = any> {
292292
event: MouseEvent | TouchEvent;
293293
distance: Point;
294294
delta: {x: -1 | 0 | 1, y: -1 | 0 | 1};
295-
}> = this._moveEvents.asObservable();
295+
}> = this._moveEvents;
296296

297297
/** Arbitrary data that can be attached to the drag item. */
298298
data: T;

0 commit comments

Comments
 (0)