| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  | import FeatureSource from "../FeatureSource"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../UIEventSource"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * A simple dummy implementation for whenever it is needed | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export default class StaticFeatureSource implements FeatureSource { | 
					
						
							|  |  |  |     public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>; | 
					
						
							|  |  |  |     public readonly name: string = "StaticFeatureSource" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-26 17:36:39 +02:00
										 |  |  |     constructor(features: any[] | UIEventSource<any[] | UIEventSource<{ feature: any, freshness: Date }>>, useFeaturesDirectly) { | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  |         const now = new Date(); | 
					
						
							| 
									
										
										
										
											2022-02-09 22:37:21 +01:00
										 |  |  |         if(features === undefined){ | 
					
						
							|  |  |  |             throw "Static feature source received undefined as source" | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-26 17:36:39 +02:00
										 |  |  |         if (useFeaturesDirectly) { | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |             // @ts-ignore
 | 
					
						
							|  |  |  |             this.features = features | 
					
						
							| 
									
										
										
										
											2021-09-26 17:36:39 +02:00
										 |  |  |         } else if (features instanceof UIEventSource) { | 
					
						
							|  |  |  |             // @ts-ignore
 | 
					
						
							| 
									
										
										
										
											2022-02-09 22:37:21 +01:00
										 |  |  |             this.features = features.map(features => features?.map(f => ({feature: f, freshness: now}) ?? [])) | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2022-02-09 22:37:21 +01:00
										 |  |  |             this.features = new UIEventSource(features?.map(f => ({ | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |                 feature: f, | 
					
						
							|  |  |  |                 freshness: now | 
					
						
							| 
									
										
										
										
											2022-02-09 22:37:21 +01:00
										 |  |  |             }))??[]) | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-21 01:47:58 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |