| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Component }              from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { HEROES }                 from './heroes'; | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   moduleId: module.id, | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  |   selector: 'flying-heroes', | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   templateUrl: 'flying-heroes.component.html', | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |   styles: ['#flyers, #all {font-style: italic}'] | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  | }) | 
					
						
							|  |  |  | // #docregion v1
 | 
					
						
							|  |  |  | export class FlyingHeroesComponent { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   heroes: any[] = []; | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  |   canFly = true; | 
					
						
							|  |  |  | // #enddocregion v1
 | 
					
						
							|  |  |  |   mutate = true; | 
					
						
							|  |  |  |   title = 'Flying Heroes (pure pipe)'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // #docregion v1
 | 
					
						
							|  |  |  |   constructor() { this.reset(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   addHero(name: string) { | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  |     name = name.trim(); | 
					
						
							|  |  |  |     if (!name) { return; } | 
					
						
							|  |  |  |     let hero = {name, canFly: this.canFly}; | 
					
						
							|  |  |  | // #enddocregion v1
 | 
					
						
							|  |  |  |     if (this.mutate) { | 
					
						
							|  |  |  |     // Pure pipe won't update display because heroes array reference is unchanged
 | 
					
						
							|  |  |  |     // Impure pipe will display
 | 
					
						
							|  |  |  | // #docregion v1
 | 
					
						
							|  |  |  | // #docregion push
 | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |     this.heroes.push(hero); | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  | // #enddocregion push
 | 
					
						
							|  |  |  | // #enddocregion v1
 | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       // Pipe updates display because heroes array is a new object
 | 
					
						
							|  |  |  | // #docregion concat
 | 
					
						
							|  |  |  |       this.heroes = this.heroes.concat(hero); | 
					
						
							|  |  |  | // #enddocregion concat
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | // #docregion v1
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   reset() { this.heroes = HEROES.slice(); } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // #enddocregion v1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ////// Identical except for impure pipe //////
 | 
					
						
							|  |  |  | // #docregion impure-component
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   moduleId: module.id, | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  |   selector: 'flying-heroes-impure', | 
					
						
							| 
									
										
										
										
											2016-09-25 18:51:54 -07:00
										 |  |  |   templateUrl: 'flying-heroes-impure.component.html', | 
					
						
							| 
									
										
										
										
											2016-01-13 15:00:43 -07:00
										 |  |  | // #enddocregion impure-component
 | 
					
						
							|  |  |  |   styles: ['.flyers, .all {font-style: italic}'], | 
					
						
							|  |  |  | // #docregion impure-component
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class FlyingHeroesImpureComponent extends FlyingHeroesComponent { | 
					
						
							|  |  |  |   title = 'Flying Heroes (impure pipe)'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // #docregion impure-component
 |