Skip to content

Commit 4dd8a31

Browse files
CaerusKarujelbourn
authored andcommitted
chore(demo-app): replace rxjs patch operators w/ lettable operators (#8548)
Fixes #8501
1 parent 461dfaf commit 4dd8a31

File tree

14 files changed

+92
-93
lines changed

14 files changed

+92
-93
lines changed

src/demo-app/a11y/table/table-a11y.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {DataSource} from '@angular/cdk/table';
1111
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
1212
import {Observable} from 'rxjs/Observable';
1313
import {MatSort, MatPaginator} from '@angular/material';
14+
import {merge} from 'rxjs/observable/merge';
15+
import {map} from 'rxjs/operators/map';
1416

1517
export interface UserData {
1618
name: string;
@@ -78,9 +80,7 @@ export class SortDataSource extends DataSource<UserData> {
7880
this._sort.sortChange,
7981
];
8082

81-
return Observable.merge(...displayDataChanges).map(() => {
82-
return this.getSortedData();
83-
});
83+
return merge(...displayDataChanges).pipe(map(() => this.getSortedData()));
8484
}
8585

8686
disconnect() {}
@@ -111,11 +111,14 @@ export class PaginatedDataSource extends DataSource<UserData> {
111111
this._paginator.page,
112112
];
113113

114-
return Observable.merge(...displayDataChanges).map(() => {
115-
const data = [...exampleData];
116-
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
117-
return data.splice(startIndex, this._paginator.pageSize);
118-
});
114+
return merge(...displayDataChanges)
115+
.pipe(
116+
map(() => {
117+
const data = [...exampleData];
118+
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
119+
return data.splice(startIndex, this._paginator.pageSize);
120+
})
121+
);
119122
}
120123

121124
disconnect() {}

src/demo-app/autocomplete/autocomplete-demo.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {Component, ViewChild, ViewEncapsulation} from '@angular/core';
1010
import {FormControl, NgModel} from '@angular/forms';
11-
import 'rxjs/add/operator/startWith';
12-
import 'rxjs/add/operator/map';
11+
import {startWith} from 'rxjs/operators/startWith';
12+
import {map} from 'rxjs/operators/map';
1313

1414
export interface State {
1515
code: string;
@@ -101,9 +101,11 @@ export class AutocompleteDemo {
101101
this.tdStates = this.states;
102102
this.stateCtrl = new FormControl({code: 'CA', name: 'California'});
103103
this.reactiveStates = this.stateCtrl.valueChanges
104-
.startWith(this.stateCtrl.value)
105-
.map(val => this.displayFn(val))
106-
.map(name => this.filterStates(name));
104+
.pipe(
105+
startWith(this.stateCtrl.value),
106+
map(val => this.displayFn(val)),
107+
map(name => this.filterStates(name))
108+
);
107109

108110
this.filteredGroupedStates = this.groupedStates = this.states.reduce((groups, state) => {
109111
let group = groups.find(g => g.letter === state.name[0]);

src/demo-app/overlay/overlay-demo.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
ViewContainerRef,
1717
ViewEncapsulation,
1818
} from '@angular/core';
19-
import 'rxjs/add/operator/do';
20-
import 'rxjs/add/operator/filter';
19+
import {filter} from 'rxjs/operators/filter';
20+
import {tap} from 'rxjs/operators/tap';
2121

2222

2323
@Component({
@@ -122,9 +122,10 @@ export class OverlayDemo {
122122
.attach(new ComponentPortal(KeyboardTrackingPanel, this.viewContainerRef));
123123

124124
overlayRef.keydownEvents()
125-
.do(e => componentRef.instance.lastKeydown = e.key)
126-
.filter(e => e.key === 'Escape')
127-
.subscribe(() => overlayRef.detach());
125+
.pipe(
126+
tap(e => componentRef.instance.lastKeydown = e.key),
127+
filter(e => e.key === 'Escape')
128+
).subscribe(() => overlayRef.detach());
128129
}
129130

130131
}

src/demo-app/table/person-data-source.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {MatPaginator, MatSort} from '@angular/material';
1010
import {DataSource} from '@angular/cdk/collections';
1111
import {Observable} from 'rxjs/Observable';
1212
import {PeopleDatabase, UserData} from './people-database';
13-
import 'rxjs/add/observable/merge';
14-
import 'rxjs/add/operator/map';
13+
import {merge} from 'rxjs/observable/merge';
14+
import {map} from 'rxjs/operators/map';
1515

1616
export class PersonDataSource extends DataSource<any> {
1717
constructor(private _peopleDatabase: PeopleDatabase,
@@ -26,13 +26,13 @@ export class PersonDataSource extends DataSource<any> {
2626
this._sort.sortChange,
2727
this._peopleDatabase.dataChange
2828
];
29-
return Observable.merge(...displayDataChanges).map(() => {
29+
return merge(...displayDataChanges).pipe(map(() => {
3030
const data = this.getSortedData();
3131

3232
// Grab the page's slice of data.
3333
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
3434
return data.splice(startIndex, this._paginator.pageSize);
35-
});
35+
}));
3636
}
3737

3838
disconnect() {

src/demo-app/table/person-detail-data-source.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import {DataSource} from '@angular/cdk/collections';
1010
import {Observable} from 'rxjs/Observable';
1111
import {UserData} from './people-database';
12-
import 'rxjs/add/observable/merge';
13-
import 'rxjs/add/operator/map';
12+
import {map} from 'rxjs/operators/map';
1413
import {PersonDataSource} from './person-data-source';
1514

1615
export interface DetailRow {
@@ -24,15 +23,15 @@ export class PersonDetailDataSource extends DataSource<any> {
2423
}
2524

2625
connect(): Observable<(UserData|DetailRow)[]> {
27-
return this._personDataSource.connect().map(data => {
26+
return this._personDataSource.connect().pipe(map(data => {
2827
const rows: (UserData|DetailRow)[] = [];
2928

3029
// Interweave a detail data object for each row data object that will be used for displaying
3130
// row details. Contains the row data.
3231
data.forEach(person => rows.push(person, {detailRow: true, data: person}));
3332

3433
return rows;
35-
});
34+
}));
3635
}
3736

3837
disconnect() {

src/demo-app/table/table-demo.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';
1313
import {DetailRow, PersonDetailDataSource} from './person-detail-data-source';
1414
import {animate, state, style, transition, trigger} from '@angular/animations';
1515
import {SelectionModel} from '@angular/cdk/collections';
16-
import {Observable} from 'rxjs/Observable';
17-
import 'rxjs/add/operator/distinctUntilChanged';
18-
import 'rxjs/add/operator/debounceTime';
19-
import 'rxjs/add/observable/fromEvent';
16+
import {distinctUntilChanged} from 'rxjs/operators/distinctUntilChanged';
17+
import {debounceTime} from 'rxjs/operators/debounceTime';
18+
import {fromEvent} from 'rxjs/observable/fromEvent';
2019

2120
export type UserProperties = 'userId' | 'userName' | 'progress' | 'color' | undefined;
2221

@@ -88,13 +87,14 @@ export class TableDemo {
8887

8988
ngOnInit() {
9089
this.connect();
91-
Observable.fromEvent(this.filter.nativeElement, 'keyup')
92-
.debounceTime(150)
93-
.distinctUntilChanged()
94-
.subscribe(() => {
95-
this.paginatorForDataSource.pageIndex = 0;
96-
this.matTableDataSource.filter = this.filter.nativeElement.value;
97-
});
90+
fromEvent(this.filter.nativeElement, 'keyup')
91+
.pipe(
92+
debounceTime(150),
93+
distinctUntilChanged()
94+
).subscribe(() => {
95+
this.paginatorForDataSource.pageIndex = 0;
96+
this.matTableDataSource.filter = this.filter.nativeElement.value;
97+
});
9898
}
9999

100100
/** Whether all filtered rows are selected. */

src/material-examples/autocomplete-display/autocomplete-display-example.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Component} from '@angular/core';
22
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs/Observable';
4-
import 'rxjs/add/operator/startWith';
5-
import 'rxjs/add/operator/map';
4+
import {startWith} from 'rxjs/operators/startWith';
5+
import {map} from 'rxjs/operators/map';
66

77
export class User {
88
constructor(public name: string) { }
@@ -30,9 +30,11 @@ export class AutocompleteDisplayExample {
3030

3131
ngOnInit() {
3232
this.filteredOptions = this.myControl.valueChanges
33-
.startWith(null)
34-
.map(user => user && typeof user === 'object' ? user.name : user)
35-
.map(name => name ? this.filter(name) : this.options.slice());
33+
.pipe(
34+
startWith({} as User),
35+
map(user => user && typeof user === 'object' ? user.name : user),
36+
map(name => name ? this.filter(name) : this.options.slice())
37+
);
3638
}
3739

3840
filter(name: string): User[] {

src/material-examples/autocomplete-filter/autocomplete-filter-example.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Component} from '@angular/core';
22
import {FormControl} from '@angular/forms';
33
import {Observable} from 'rxjs/Observable';
4-
import 'rxjs/add/operator/startWith';
5-
import 'rxjs/add/operator/map';
4+
import {startWith} from 'rxjs/operators/startWith';
5+
import {map} from 'rxjs/operators/map';
66

77
/**
88
* @title Filter autocomplete
@@ -24,15 +24,17 @@ export class AutocompleteFilterExample {
2424

2525
filteredOptions: Observable<string[]>;
2626

27-
ngOnInit() {
28-
this.filteredOptions = this.myControl.valueChanges
29-
.startWith('')
30-
.map(val => this.filter(val));
31-
}
27+
ngOnInit() {
28+
this.filteredOptions = this.myControl.valueChanges
29+
.pipe(
30+
startWith(''),
31+
map(val => this.filter(val))
32+
);
33+
}
3234

33-
filter(val: string): string[] {
34-
return this.options.filter(option =>
35-
option.toLowerCase().indexOf(val.toLowerCase()) === 0);
36-
}
35+
filter(val: string): string[] {
36+
return this.options.filter(option =>
37+
option.toLowerCase().indexOf(val.toLowerCase()) === 0);
38+
}
3739

3840
}

src/material-examples/autocomplete-overview/autocomplete-overview-example.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import {Component} from '@angular/core';
22
import {FormControl} from '@angular/forms';
33

44
import {Observable} from 'rxjs/Observable';
5-
import 'rxjs/add/operator/startWith';
6-
import 'rxjs/add/operator/map';
5+
import {startWith} from 'rxjs/operators/startWith';
6+
import {map} from 'rxjs/operators/map';
7+
8+
export class State {
9+
constructor(public name: string, public population: string, public flag: string) { }
10+
}
711

812
/**
913
* @title Autocomplete overview
@@ -17,7 +21,7 @@ export class AutocompleteOverviewExample {
1721
stateCtrl: FormControl;
1822
filteredStates: Observable<any[]>;
1923

20-
states: any[] = [
24+
states: State[] = [
2125
{
2226
name: 'Arkansas',
2327
population: '2.978M',
@@ -47,8 +51,10 @@ export class AutocompleteOverviewExample {
4751
constructor() {
4852
this.stateCtrl = new FormControl();
4953
this.filteredStates = this.stateCtrl.valueChanges
50-
.startWith(null)
51-
.map(state => state ? this.filterStates(state) : this.states.slice());
54+
.pipe(
55+
startWith(''),
56+
map(state => state ? this.filterStates(state) : this.states.slice())
57+
);
5258
}
5359

5460
filterStates(name: string) {

src/material-examples/cdk-table-basic/cdk-table-basic-example.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import {Component} from '@angular/core';
22
import {DataSource} from '@angular/cdk/collections';
33
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
44
import {Observable} from 'rxjs/Observable';
5-
import 'rxjs/add/operator/startWith';
6-
import 'rxjs/add/observable/merge';
7-
import 'rxjs/add/operator/map';
85

96
/**
107
* @title Basic CDK data-table

src/material-examples/table-http/table-http-example.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {Component, AfterViewInit, ViewChild} from '@angular/core';
22
import {HttpClient} from '@angular/common/http';
33
import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';
44
import {Observable} from 'rxjs/Observable';
5-
import 'rxjs/add/observable/merge';
6-
import 'rxjs/add/observable/of';
7-
import 'rxjs/add/operator/catch';
8-
import 'rxjs/add/operator/map';
9-
import 'rxjs/add/operator/startWith';
10-
import 'rxjs/add/operator/switchMap';
5+
import {merge} from 'rxjs/observable/merge';
6+
import {of as observableOf} from 'rxjs/observable/of';
7+
import {catchError} from 'rxjs/operators/catchError';
8+
import {map} from 'rxjs/operators/map';
9+
import {startWith} from 'rxjs/operators/startWith';
10+
import {switchMap} from 'rxjs/operators/switchMap';
1111

1212
/**
1313
* @title Table retrieving data through HTTP
@@ -37,28 +37,29 @@ export class TableHttpExample implements AfterViewInit {
3737
// If the user changes the sort order, reset back to the first page.
3838
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
3939

40-
Observable.merge(this.sort.sortChange, this.paginator.page)
41-
.startWith(null)
42-
.switchMap(() => {
40+
merge(this.sort.sortChange, this.paginator.page)
41+
.pipe(
42+
startWith({}),
43+
switchMap(() => {
4344
this.isLoadingResults = true;
4445
return this.exampleDatabase!.getRepoIssues(
45-
this.sort.active, this.sort.direction, this.paginator.pageIndex);
46-
})
47-
.map(data => {
46+
this.sort.active, this.sort.direction, this.paginator.pageIndex);
47+
}),
48+
map(data => {
4849
// Flip flag to show that loading has finished.
4950
this.isLoadingResults = false;
5051
this.isRateLimitReached = false;
5152
this.resultsLength = data.total_count;
5253

5354
return data.items;
54-
})
55-
.catch(() => {
55+
}),
56+
catchError(() => {
5657
this.isLoadingResults = false;
5758
// Catch if the GitHub API has reached its rate limit. Return empty data.
5859
this.isRateLimitReached = true;
59-
return Observable.of([]);
60+
return observableOf([]);
6061
})
61-
.subscribe(data => this.dataSource.data = data);
62+
).subscribe(data => this.dataSource.data = data);
6263
}
6364
}
6465

src/universal-app/kitchen-sink/kitchen-sink.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Component, NgModule} from '@angular/core';
22
import {ServerModule} from '@angular/platform-server';
33
import {BrowserModule} from '@angular/platform-browser';
4-
import {Observable} from 'rxjs/Observable';
54
import {
65
MatAutocompleteModule,
76
MatButtonModule,
@@ -42,7 +41,7 @@ import {
4241
DataSource
4342
} from '@angular/cdk/table';
4443

45-
import 'rxjs/add/observable/of';
44+
import {of as observableOf} from 'rxjs/observable/of';
4645

4746
@Component({
4847
selector: 'kitchen-sink',
@@ -56,7 +55,7 @@ export class KitchenSink {
5655

5756
/** Data source for the CDK and Material table. */
5857
tableDataSource: DataSource<any> = {
59-
connect: () => Observable.of([{userId: 1}, {userId: 2}]),
58+
connect: () => observableOf([{userId: 1}, {userId: 2}]),
6059
disconnect: () => {}
6160
};
6261

tools/package-tools/rollup-globals.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,4 @@ export const rollupGlobals = {
8686
'rxjs/operators/share': 'Rx.Observable',
8787
'rxjs/operators/delay': 'Rx.Observable',
8888
'rxjs/operators/combineLatest': 'Rx.Observable',
89-
90-
'rxjs/add/observable/merge': 'Rx.Observable',
91-
'rxjs/add/observable/fromEvent': 'Rx.Observable',
92-
'rxjs/add/observable/of': 'Rx.Observable',
93-
'rxjs/add/observable/interval': 'Rx.Observable',
94-
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
95-
'rxjs/add/operator/map': 'Rx.Observable.prototype',
96-
'rxjs/add/operator/debounceTime': 'Rx.Observable.prototype',
97-
'rxjs/add/operator/distinctUntilChanged': 'Rx.Observable.prototype',
98-
'rxjs/add/operator/first': 'Rx.Observable.prototype',
99-
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
100-
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype'
10189
};

0 commit comments

Comments
 (0)