forked from MapComplete/MapComplete
		
	Reformat all files with prettier
This commit is contained in:
		
							parent
							
								
									e22d189376
								
							
						
					
					
						commit
						b541d3eab4
					
				
					 382 changed files with 50893 additions and 35566 deletions
				
			
		|  | @ -1,51 +1,47 @@ | |||
| import {UIEventSource} from "../UIEventSource"; | ||||
| import {Utils} from "../../Utils"; | ||||
| import { UIEventSource } from "../UIEventSource" | ||||
| import { Utils } from "../../Utils" | ||||
| 
 | ||||
| /** | ||||
|  * Fetches data from random data sources, used in the metatagging | ||||
|  */ | ||||
| export default class LiveQueryHandler { | ||||
| 
 | ||||
|     private static neededShorthands = {} // url -> (shorthand:paths)[]
 | ||||
| 
 | ||||
|     public static FetchLiveData(url: string, shorthands: string[]): UIEventSource<any /* string -> string */> { | ||||
| 
 | ||||
|     public static FetchLiveData( | ||||
|         url: string, | ||||
|         shorthands: string[] | ||||
|     ): UIEventSource<any /* string -> string */> { | ||||
|         const shorthandsSet: string[] = LiveQueryHandler.neededShorthands[url] ?? [] | ||||
| 
 | ||||
|         for (const shorthand of shorthands) { | ||||
|             if (shorthandsSet.indexOf(shorthand) < 0) { | ||||
|                 shorthandsSet.push(shorthand); | ||||
|                 shorthandsSet.push(shorthand) | ||||
|             } | ||||
|         } | ||||
|         LiveQueryHandler.neededShorthands[url] = shorthandsSet; | ||||
| 
 | ||||
|         LiveQueryHandler.neededShorthands[url] = shorthandsSet | ||||
| 
 | ||||
|         if (LiveQueryHandler[url] === undefined) { | ||||
|             const source = new UIEventSource({}); | ||||
|             LiveQueryHandler[url] = source; | ||||
|             const source = new UIEventSource({}) | ||||
|             LiveQueryHandler[url] = source | ||||
| 
 | ||||
|             console.log("Fetching live data from a third-party (unknown) API:", url) | ||||
|             Utils.downloadJson(url).then(data => { | ||||
|             Utils.downloadJson(url).then((data) => { | ||||
|                 for (const shorthandDescription of shorthandsSet) { | ||||
| 
 | ||||
|                     const descr = shorthandDescription.trim().split(":"); | ||||
|                     const shorthand = descr[0]; | ||||
|                     const path = descr[1]; | ||||
|                     const parts = path.split("."); | ||||
|                     let trail = data; | ||||
|                     const descr = shorthandDescription.trim().split(":") | ||||
|                     const shorthand = descr[0] | ||||
|                     const path = descr[1] | ||||
|                     const parts = path.split(".") | ||||
|                     let trail = data | ||||
|                     for (const part of parts) { | ||||
|                         if (trail !== undefined) { | ||||
|                             trail = trail[part]; | ||||
|                             trail = trail[part] | ||||
|                         } | ||||
|                     } | ||||
|                     source.data[shorthand] = trail; | ||||
|                     source.data[shorthand] = trail | ||||
|                 } | ||||
|                 source.ping(); | ||||
| 
 | ||||
|                 source.ping() | ||||
|             }) | ||||
| 
 | ||||
|         } | ||||
|         return LiveQueryHandler[url]; | ||||
|         return LiveQueryHandler[url] | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue