| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { ReadonlyInputElement } from "./InputElement" | 
					
						
							|  |  |  | import { Store } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import { VariableUiElement } from "../Base/VariableUIElement" | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | export default class VariableInputElement<T> | 
					
						
							|  |  |  |     extends BaseUIElement | 
					
						
							|  |  |  |     implements ReadonlyInputElement<T> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     private readonly value: Store<T> | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  |     private readonly element: BaseUIElement | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private readonly upstream: Store<ReadonlyInputElement<T>> | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 19:37:22 +02:00
										 |  |  |     constructor(upstream: Store<ReadonlyInputElement<T>>) { | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  |         super() | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         this.upstream = upstream | 
					
						
							|  |  |  |         this.value = upstream.bind((v) => v.GetValue()) | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  |         this.element = new VariableUiElement(upstream) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-05 02:24:14 +02:00
										 |  |  |     GetValue(): Store<T> { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this.value | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IsValid(t: T): boolean { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this.upstream.data.IsValid(t) | 
					
						
							| 
									
										
										
										
											2021-10-03 21:44:43 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |     protected InnerConstructElement(): HTMLElement { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this.element.ConstructElement() | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |