| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { InputElement } from "./InputElement" | 
					
						
							|  |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  | import Combine from "../Base/Combine" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  | export default class CombinedInputElement<T, J, X> extends InputElement<X> { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private readonly _a: InputElement<T> | 
					
						
							|  |  |  |     private readonly _b: InputElement<J> | 
					
						
							|  |  |  |     private readonly _combined: BaseUIElement | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     private readonly _value: UIEventSource<X> | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private readonly _split: (x: X) => [T, J] | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     constructor( | 
					
						
							|  |  |  |         a: InputElement<T>, | 
					
						
							|  |  |  |         b: InputElement<J>, | 
					
						
							|  |  |  |         combine: (t: T, j: J) => X, | 
					
						
							|  |  |  |         split: (x: X) => [T, J] | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         super() | 
					
						
							|  |  |  |         this._a = a | 
					
						
							|  |  |  |         this._b = b | 
					
						
							|  |  |  |         this._split = split | 
					
						
							|  |  |  |         this._combined = new Combine([this._a, this._b]) | 
					
						
							| 
									
										
										
										
											2022-06-06 19:37:22 +02:00
										 |  |  |         this._value = this._a.GetValue().sync( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             (t) => combine(t, this._b?.GetValue()?.data), | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |             [this._b.GetValue()], | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             (x) => { | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |                 const [t, j] = split(x) | 
					
						
							| 
									
										
										
										
											2021-06-24 02:33:26 +02:00
										 |  |  |                 this._b.GetValue()?.setData(j) | 
					
						
							| 
									
										
										
										
											2022-06-06 19:37:22 +02:00
										 |  |  |                 return t | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     GetValue(): UIEventSource<X> { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this._value | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     IsValid(x: X): boolean { | 
					
						
							|  |  |  |         const [t, j] = this._split(x) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this._a.IsValid(t) && this._b.IsValid(j) | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     protected InnerConstructElement(): HTMLElement { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return this._combined.ConstructElement() | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |