mapcomplete/UI/Input/VariableInputElement.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
944 B
TypeScript
Raw Normal View History

2022-06-06 19:37:22 +02:00
import { ReadonlyInputElement } from "./InputElement"
import { Store } from "../../Logic/UIEventSource"
import BaseUIElement from "../BaseUIElement"
import { VariableUiElement } from "../Base/VariableUIElement"
export default class VariableInputElement<T>
extends BaseUIElement
implements ReadonlyInputElement<T>
{
private readonly value: Store<T>
private readonly element: BaseUIElement
2022-06-06 19:37:22 +02:00
private readonly upstream: Store<ReadonlyInputElement<T>>
2022-06-06 19:37:22 +02:00
constructor(upstream: Store<ReadonlyInputElement<T>>) {
super()
this.upstream = upstream
this.value = upstream.bind((v) => v.GetValue())
this.element = new VariableUiElement(upstream)
}
GetValue(): Store<T> {
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()
}
}