| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  | import {InputElement} from "./InputElement"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  | 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> { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     private readonly _a: InputElement<T>; | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     private readonly _b: InputElement<J>; | 
					
						
							| 
									
										
										
										
											2021-06-10 01:36:20 +02:00
										 |  |  |     private readonly _combined: BaseUIElement; | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |     private readonly _value: UIEventSource<X> | 
					
						
							|  |  |  |     private readonly _split: (x: X) => [T, J]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(a: InputElement<T>, b: InputElement<J>, | 
					
						
							|  |  |  |                 combine: (t: T, j: J) => X, | 
					
						
							|  |  |  |                 split: (x: X) => [T, J]) { | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |         super(); | 
					
						
							|  |  |  |         this._a = a; | 
					
						
							|  |  |  |         this._b = b; | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |         this._split = split; | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |         this._combined = new Combine([this._a, this._b]); | 
					
						
							| 
									
										
										
										
											2022-06-06 19:37:22 +02:00
										 |  |  |         this._value = this._a.GetValue().sync( | 
					
						
							| 
									
										
										
										
											2021-06-24 02:33:26 +02:00
										 |  |  |             t => combine(t, this._b?.GetValue()?.data), | 
					
						
							| 
									
										
										
										
											2021-06-22 03:16:45 +02:00
										 |  |  |             [this._b.GetValue()], | 
					
						
							| 
									
										
										
										
											2022-06-06 19:37:22 +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> { | 
					
						
							|  |  |  |         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) | 
					
						
							|  |  |  |         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 { | 
					
						
							|  |  |  |         return this._combined.ConstructElement(); | 
					
						
							| 
									
										
										
										
											2020-09-26 03:02:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |