| 
									
										
										
										
											2015-12-12 22:01:46 -08:00
										 |  |  | /// <reference path='./window.extension.d.ts'/>
 | 
					
						
							| 
									
										
										
										
											2015-11-02 00:28:38 -08:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2015-12-28 11:52:41 -08:00
										 |  |  | import {Pipe, PipeTransform} from 'angular2/core'; | 
					
						
							| 
									
										
										
										
											2015-11-02 00:28:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // #docregion pipe-metadata
 | 
					
						
							|  |  |  | @Pipe({ | 
					
						
							|  |  |  |   name: 'fetch', | 
					
						
							|  |  |  |   pure: false | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | // #enddocregion pipe-metadata
 | 
					
						
							| 
									
										
										
										
											2015-12-28 11:52:41 -08:00
										 |  |  | export class FetchJsonPipe  implements PipeTransform{ | 
					
						
							| 
									
										
										
										
											2015-11-02 00:28:38 -08:00
										 |  |  |   private fetchedValue:any; | 
					
						
							|  |  |  |   private fetchPromise:Promise<any>; | 
					
						
							| 
									
										
										
										
											2015-12-12 22:01:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-02 00:28:38 -08:00
										 |  |  |   transform(value:string, args:string[]):any { | 
					
						
							|  |  |  |     if (!this.fetchPromise) { | 
					
						
							|  |  |  |       this.fetchPromise = window.fetch(value) | 
					
						
							| 
									
										
										
										
											2015-12-12 22:01:46 -08:00
										 |  |  |         .then((result:any) => result.json()) | 
					
						
							|  |  |  |         .then((json:any)   => this.fetchedValue = json); | 
					
						
							| 
									
										
										
										
											2015-11-02 00:28:38 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return this.fetchedValue; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |