Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit aa6f503

Browse files
authored
docs: remove rxjs-extensions in favor of explict imports (#3075)
Triggered by #2620 which it closes.
1 parent 0d5877d commit aa6f503

26 files changed

+180
-210
lines changed

public/docs/_examples/pipes/ts/app/fetch-json.pipe.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// #docregion
22
import { Pipe, PipeTransform } from '@angular/core';
33
import { Http } from '@angular/http';
4-
import './rxjs-extensions';
4+
5+
import 'rxjs/add/operator/map';
56

67
// #docregion pipe-metadata
78
@Pipe({

public/docs/_examples/pipes/ts/app/hero-async-message.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// #docregion
22
import { Component } from '@angular/core';
3+
34
import { Observable } from 'rxjs/Observable';
4-
import './rxjs-extensions';
5+
import 'rxjs/add/observable/interval';
6+
import 'rxjs/add/operator/map';
7+
import 'rxjs/add/operator/take';
58

69
@Component({
710
selector: 'hero-message',

public/docs/_examples/pipes/ts/app/rxjs-extensions.ts

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
// #docplaster
21
// #docregion
32
import { Component } from '@angular/core';
43

5-
// #docregion import-rxjs
6-
// Add the RxJS Observable operators.
7-
import './rxjs-operators';
8-
// #enddocregion import-rxjs
9-
104
@Component({
115
selector: 'my-app',
126
template: `
@@ -17,4 +11,3 @@ import './rxjs-operators';
1711
`
1812
})
1913
export class AppComponent { }
20-
// #enddocregion

public/docs/_examples/server-communication/ts/app/app.module.1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// #docregion
2-
import { NgModule } from '@angular/core';
2+
import { NgModule } from '@angular/core';
33
import { BrowserModule } from '@angular/platform-browser';
4-
import { FormsModule } from '@angular/forms';
4+
import { FormsModule } from '@angular/forms';
55
import { HttpModule, JsonpModule } from '@angular/http';
66

77
import { AppComponent } from './app.component';

public/docs/_examples/server-communication/ts/app/app.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// #docplaster
22
// #docregion
3-
import { NgModule } from '@angular/core';
3+
import { NgModule } from '@angular/core';
44
import { BrowserModule } from '@angular/platform-browser';
5-
import { FormsModule } from '@angular/forms';
5+
import { FormsModule } from '@angular/forms';
66
import { HttpModule, JsonpModule } from '@angular/http';
77

88

public/docs/_examples/server-communication/ts/app/rxjs-operators.ts

-16
This file was deleted.

public/docs/_examples/server-communication/ts/app/toh/hero.service.promise.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// #docplaster
22
// #docregion
33
// Promise Version
4-
import { Injectable } from '@angular/core';
5-
import { Http, Response } from '@angular/http';
4+
import { Injectable } from '@angular/core';
5+
import { Http, Response } from '@angular/http';
66
import { Headers, RequestOptions } from '@angular/http';
7-
import { Hero } from './hero';
7+
8+
// #docregion rxjs-imports
9+
import 'rxjs/add/operator/toPromise';
10+
// #enddocregion rxjs-imports
11+
12+
import { Hero } from './hero';
813

914
@Injectable()
1015
export class HeroService {

public/docs/_examples/server-communication/ts/app/toh/hero.service.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
// #docregion
33
// Observable Version
44
// #docregion v1
5-
import { Injectable } from '@angular/core';
6-
import { Http, Response } from '@angular/http';
5+
import { Injectable } from '@angular/core';
6+
import { Http, Response } from '@angular/http';
77
// #enddocregion v1
88
// #docregion import-request-options
99
import { Headers, RequestOptions } from '@angular/http';
1010
// #enddocregion import-request-options
1111
// #docregion v1
1212

13-
import { Hero } from './hero';
14-
import { Observable } from 'rxjs/Observable';
13+
// #docregion rxjs-imports
14+
import { Observable } from 'rxjs/Observable';
15+
import 'rxjs/add/operator/catch';
16+
import 'rxjs/add/operator/map';
17+
// #enddocregion rxjs-imports
18+
19+
import { Hero } from './hero';
1520

1621
@Injectable()
1722
export class HeroService {

public/docs/_examples/server-communication/ts/app/wiki/wiki-smart.component.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
/* tslint:disable: member-ordering forin */
22
// #docplaster
33
// #docregion
4-
import { Component, OnInit } from '@angular/core';
5-
import { Observable } from 'rxjs/Observable';
4+
import { Component, OnInit } from '@angular/core';
5+
6+
// #docregion rxjs-imports
7+
import { Observable } from 'rxjs/Observable';
8+
import 'rxjs/add/operator/debounceTime';
9+
import 'rxjs/add/operator/distinctUntilChanged';
10+
import 'rxjs/add/operator/switchMap';
11+
612
// #docregion import-subject
7-
import { Subject } from 'rxjs/Subject';
13+
import { Subject } from 'rxjs/Subject';
814
// #enddocregion import-subject
915

1016
import { WikipediaService } from './wikipedia.service';
1117

1218
@Component({
1319
moduleId: module.id,
1420
selector: 'my-wiki-smart',
15-
templateUrl: './wiki.component.html',
21+
template: `
22+
<h1>Smarter Wikipedia Demo</h1>
23+
<p>Search when typing stops</p>
24+
<input #term (keyup)="search(term.value)"/>
25+
<ul>
26+
<li *ngFor="let item of items | async">{{item}}</li>
27+
</ul>`,
1628
providers: [ WikipediaService ]
1729
})
1830
export class WikiSmartComponent implements OnInit {
19-
title = 'Smarter Wikipedia Demo';
20-
fetches = 'Fetches when typing stops';
2131
items: Observable<string[]>;
2232

33+
constructor (private wikipediaService: WikipediaService) {}
34+
2335
// #docregion subject
2436
private searchTermStream = new Subject<string>();
2537
search(term: string) { this.searchTermStream.next(term); }
2638
// #enddocregion subject
2739

28-
constructor (private wikipediaService: WikipediaService) {}
29-
3040
ngOnInit() {
3141
// #docregion observable-operators
3242
this.items = this.searchTermStream

public/docs/_examples/server-communication/ts/app/wiki/wiki.component.html

-11
This file was deleted.

public/docs/_examples/server-communication/ts/app/wiki/wiki.component.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import { Observable } from 'rxjs/Observable';
55
import { WikipediaService } from './wikipedia.service';
66

77
@Component({
8-
moduleId: module.id,
98
selector: 'my-wiki',
10-
templateUrl: 'wiki.component.html',
9+
template: `
10+
<h1>Wikipedia Demo</h1>
11+
<p>Search after each keystroke</p>
12+
<input #term (keyup)="search(term.value)"/>
13+
<ul>
14+
<li *ngFor="let item of items | async">{{item}}</li>
15+
</ul>`,
1116
providers: [ WikipediaService ]
1217
})
1318
export class WikiComponent {
14-
title = 'Wikipedia Demo';
15-
fetches = 'Fetches after each keystroke';
1619
items: Observable<string[]>;
1720

21+
constructor (private wikipediaService: WikipediaService) { }
22+
1823
search (term: string) {
1924
this.items = this.wikipediaService.search(term);
2025
}
21-
22-
constructor (private wikipediaService: WikipediaService) { }
2326
}

public/docs/_examples/server-communication/ts/app/wiki/wikipedia.service.1.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { Injectable } from '@angular/core';
44
import { Jsonp } from '@angular/http';
55

6+
import 'rxjs/add/operator/map';
7+
68
@Injectable()
79
export class WikipediaService {
810
constructor(private jsonp: Jsonp) { }

public/docs/_examples/server-communication/ts/app/wiki/wikipedia.service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { Injectable } from '@angular/core';
33
import { Jsonp, URLSearchParams } from '@angular/http';
44

5+
import 'rxjs/add/operator/map';
6+
57
@Injectable()
68
export class WikipediaService {
79
constructor(private jsonp: Jsonp) {}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// #docregion
22
export * from './logger.service';
3-
export * from './rxjs-extensions';
43
export * from './spinner/spinner.service';
54
export * from './nav/nav.component';

public/docs/_examples/style-guide/ts/04-11/app/core/rxjs-extensions.ts

-7
This file was deleted.

public/docs/_examples/style-guide/ts/05-15/app/heroes/hero-list/hero-list.component.avoid.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
import { OnInit } from '@angular/core';
55
import { Http, Response } from '@angular/http';
6+
67
import { Observable } from 'rxjs/Observable';
8+
import 'rxjs/add/operator/catch';
9+
import 'rxjs/add/operator/finally';
10+
import 'rxjs/add/operator/map';
711

812
import { Hero } from '../shared/hero.model';
913

public/docs/_examples/style-guide/ts/05-15/app/heroes/shared/hero.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// #docregion
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs/Rx';
3+
4+
import { Observable } from 'rxjs/Observable';
5+
import 'rxjs/add/observable/of';
46

57
import { Hero } from './hero.model';
68

public/docs/_examples/style-guide/ts/07-03/app/heroes/shared/hero.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// #docregion
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs/Rx';
3+
4+
import { Observable } from 'rxjs/Observable';
5+
import 'rxjs/add/observable/of';
46

57
import { Hero } from './hero.model';
68

public/docs/_examples/style-guide/ts/07-04/app/heroes/shared/hero.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// #docregion
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs/Rx';
3+
4+
import { Observable } from 'rxjs/Observable';
5+
import 'rxjs/add/observable/of';
46

57
import { Hero } from './hero.model';
68

public/docs/_examples/toh-6/ts/app/app.module.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// #docplaster
22
// #docregion
3-
// #docregion rxjs-extensions
4-
import './rxjs-extensions';
5-
// #enddocregion rxjs-extensions
6-
73
// #docregion v1, v2
84
import { NgModule } from '@angular/core';
95
import { BrowserModule } from '@angular/platform-browser';

public/docs/_examples/toh-6/ts/app/hero-search.component.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
// #docregion
33
import { Component, OnInit } from '@angular/core';
44
import { Router } from '@angular/router';
5+
6+
// #docregion rxjs-imports
57
import { Observable } from 'rxjs/Observable';
68
import { Subject } from 'rxjs/Subject';
79

10+
// Observable class extensions
11+
import 'rxjs/add/observable/of';
12+
13+
// Observable operators
14+
import 'rxjs/add/operator/catch';
15+
import 'rxjs/add/operator/debounceTime';
16+
import 'rxjs/add/operator/distinctUntilChanged';
17+
// #enddocregion rxjs-imports
18+
819
import { HeroSearchService } from './hero-search.service';
920
import { Hero } from './hero';
1021

@@ -37,15 +48,15 @@ export class HeroSearchComponent implements OnInit {
3748

3849
ngOnInit(): void {
3950
this.heroes = this.searchTerms
40-
.debounceTime(300) // wait for 300ms pause in events
51+
.debounceTime(300) // wait 300ms after each keystroke before considering the term
4152
.distinctUntilChanged() // ignore if next search term is same as previous
42-
.switchMap(term => term // switch to new observable each time
53+
.switchMap(term => term // switch to new observable each time the term changes
4354
// return the http search observable
4455
? this.heroSearchService.search(term)
45-
// or the observable of empty heroes if no search term
56+
// or the observable of empty heroes if there was no search term
4657
: Observable.of<Hero[]>([]))
4758
.catch(error => {
48-
// TODO: real error handling
59+
// TODO: add real error handling
4960
console.log(error);
5061
return Observable.of<Hero[]>([]);
5162
});
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// #docregion
2-
import { Injectable } from '@angular/core';
3-
import { Http, Response } from '@angular/http';
4-
import { Observable } from 'rxjs';
2+
import { Injectable } from '@angular/core';
3+
import { Http } from '@angular/http';
4+
5+
import { Observable } from 'rxjs/Observable';
6+
import 'rxjs/add/operator/map';
57

68
import { Hero } from './hero';
79

@@ -13,6 +15,6 @@ export class HeroSearchService {
1315
search(term: string): Observable<Hero[]> {
1416
return this.http
1517
.get(`app/heroes/?name=${term}`)
16-
.map((r: Response) => r.json().data as Hero[]);
18+
.map(response => response.json().data as Hero[]);
1719
}
1820
}

public/docs/_examples/toh-6/ts/app/rxjs-extensions.ts

-13
This file was deleted.

0 commit comments

Comments
 (0)