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