| 
									
										
										
										
											2016-10-19 23:17:50 -07:00
										 |  |  | /* tslint:disable: member-ordering forin */ | 
					
						
							|  |  |  | // #docplaster
 | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Component }        from '@angular/core'; | 
					
						
							|  |  |  | import { Observable }       from 'rxjs/Observable'; | 
					
						
							| 
									
										
										
										
											2016-02-03 22:28:39 -08:00
										 |  |  | // #docregion import-subject
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Subject }          from 'rxjs/Subject'; | 
					
						
							| 
									
										
										
										
											2016-02-03 22:28:39 -08:00
										 |  |  | // #enddocregion import-subject
 | 
					
						
							| 
									
										
										
										
											2016-02-02 11:22:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { WikipediaService } from './wikipedia.service'; | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							| 
									
										
										
										
											2016-10-19 23:17:50 -07:00
										 |  |  |   moduleId: module.id, | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  |   selector: 'my-wiki-smart', | 
					
						
							| 
									
										
										
										
											2016-10-19 23:17:50 -07:00
										 |  |  |   templateUrl: 'wiki.component.html', | 
					
						
							|  |  |  |   providers: [ WikipediaService ] | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | }) | 
					
						
							|  |  |  | export class WikiSmartComponent { | 
					
						
							| 
									
										
										
										
											2016-10-19 23:17:50 -07:00
										 |  |  |   title   = 'Smarter Wikipedia Demo'; | 
					
						
							|  |  |  |   fetches = 'Fetches when typing stops'; | 
					
						
							|  |  |  |   items: Observable<string[]>; | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-03 22:28:39 -08:00
										 |  |  |   // #docregion subject
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   private searchTermStream = new Subject<string>(); | 
					
						
							| 
									
										
										
										
											2016-05-17 01:45:52 -07:00
										 |  |  |   search(term: string) { this.searchTermStream.next(term); } | 
					
						
							| 
									
										
										
										
											2016-02-03 22:28:39 -08:00
										 |  |  |   // #enddocregion subject
 | 
					
						
							| 
									
										
										
										
											2016-02-02 11:22:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 23:17:50 -07:00
										 |  |  |   constructor (private wikipediaService: WikipediaService) { | 
					
						
							|  |  |  |     // #docregion observable-operators
 | 
					
						
							|  |  |  |     this.items = this.searchTermStream | 
					
						
							|  |  |  |       .debounceTime(300) | 
					
						
							|  |  |  |       .distinctUntilChanged() | 
					
						
							|  |  |  |       .switchMap((term: string) => this.wikipediaService.search(term)); | 
					
						
							|  |  |  |     // #enddocregion observable-operators
 | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | } |