Skip to content

Commit 2ed5f7d

Browse files
crisbetommalerba
authored andcommitted
refactor: remove usages of deprecated rxjs apis (#10866)
Removes the following APIs that are deprecated as of RxJS 6.0: * Replaces usages of `empty()` with `EMPTY`. * Replaces uses of the `resultSelector` parameter of `combineLatest` with calls to `map`.
1 parent 5920bc3 commit 2ed5f7d

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/cdk/layout/breakpoints-observer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ export class BreakpointObserver implements OnDestroy {
5959
const queries = splitQueries(coerceArray(value));
6060
const observables = queries.map(query => this._registerQuery(query).observable);
6161

62-
return combineLatest(observables, (a: BreakpointState, b: BreakpointState) => {
62+
return combineLatest(observables).pipe(map((breakpointStates: BreakpointState[]) => {
6363
return {
64-
matches: !!((a && a.matches) || (b && b.matches)),
64+
matches: breakpointStates.some(state => state && state.matches)
6565
};
66-
});
66+
}));
6767
}
6868

6969
/** Registers a specific query to be listened for. */

src/cdk/table/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ts_library(
2222
":table",
2323
"//src/cdk/collections",
2424
"@rxjs",
25+
"@rxjs//operators"
2526
],
2627
tsconfig = "//src/cdk:tsconfig-build.json",
2728
)

src/cdk/table/table.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {ComponentFixture, TestBed, fakeAsync, flush} from '@angular/core/testing
1111
import {CdkTable} from './table';
1212
import {CollectionViewer, DataSource} from '@angular/cdk/collections';
1313
import {combineLatest, BehaviorSubject, Observable} from 'rxjs';
14+
import {map} from 'rxjs/operators';
1415
import {CdkTableModule} from './index';
1516
import {
1617
getTableDuplicateColumnNameError,
@@ -832,7 +833,7 @@ class FakeDataSource extends DataSource<TestData> {
832833
connect(collectionViewer: CollectionViewer) {
833834
this.isConnected = true;
834835
const streams = [this._dataChange, collectionViewer.viewChange];
835-
return combineLatest(streams, (data, _) => data);
836+
return combineLatest<TestData[]>(streams).pipe(map(data => data[0]));
836837
}
837838

838839
disconnect() {

src/cdk/text-field/autofill.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {supportsPassiveEventListeners} from '@angular/cdk/platform';
1010
import {Component, ElementRef, ViewChild} from '@angular/core';
1111
import {ComponentFixture, inject, TestBed} from '@angular/core/testing';
12-
import {empty as observableEmpty} from 'rxjs';
12+
import {EMPTY} from 'rxjs';
1313
import {AutofillEvent, AutofillMonitor} from './autofill';
1414
import {TextFieldModule} from './text-field-module';
1515

@@ -166,7 +166,7 @@ describe('cdkAutofill', () => {
166166

167167
beforeEach(inject([AutofillMonitor], (afm: AutofillMonitor) => {
168168
autofillMonitor = afm;
169-
spyOn(autofillMonitor, 'monitor').and.returnValue(observableEmpty());
169+
spyOn(autofillMonitor, 'monitor').and.returnValue(EMPTY);
170170
spyOn(autofillMonitor, 'stopMonitoring');
171171
fixture = TestBed.createComponent(InputWithCdkAutofilled);
172172
testComponent = fixture.componentInstance;

src/cdk/text-field/autofill.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
OnInit,
1818
Output,
1919
} from '@angular/core';
20-
import {empty, Observable, Subject} from 'rxjs';
20+
import {EMPTY, Observable, Subject} from 'rxjs';
2121

2222

2323
/** An event that is emitted when the autofill state of an input changes. */
@@ -58,7 +58,7 @@ export class AutofillMonitor implements OnDestroy {
5858
*/
5959
monitor(element: Element): Observable<AutofillEvent> {
6060
if (!this._platform.isBrowser) {
61-
return empty();
61+
return EMPTY;
6262
}
6363

6464
const info = this._monitoredElements.get(element);

src/lib/table/table-data-source.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {_isNumberValue} from '@angular/cdk/coercion';
1010
import {DataSource} from '@angular/cdk/table';
1111
import {MatPaginator, PageEvent} from '@angular/material/paginator';
1212
import {MatSort, Sort} from '@angular/material/sort';
13-
import {BehaviorSubject, combineLatest, empty, Observable, Subscription} from 'rxjs';
13+
import {BehaviorSubject, combineLatest, EMPTY, Observable, Subscription} from 'rxjs';
1414
import {map, startWith} from 'rxjs/operators';
1515

1616

@@ -175,8 +175,8 @@ export class MatTableDataSource<T> extends DataSource<T> {
175175
_updateChangeSubscription() {
176176
// Sorting and/or pagination should be watched if MatSort and/or MatPaginator are provided.
177177
// Otherwise, use an empty observable stream to take their place.
178-
const sortChange: Observable<Sort> = this._sort ? this._sort.sortChange : empty();
179-
const pageChange: Observable<PageEvent> = this._paginator ? this._paginator.page : empty();
178+
const sortChange: Observable<Sort> = this._sort ? this._sort.sortChange : EMPTY;
179+
const pageChange: Observable<PageEvent> = this._paginator ? this._paginator.page : EMPTY;
180180

181181
if (this._renderChangesSubscription) {
182182
this._renderChangesSubscription.unsubscribe();

0 commit comments

Comments
 (0)