forked from MapComplete/MapComplete
More refactoring and fixes
This commit is contained in:
parent
1bc7d9118a
commit
9877abec17
14 changed files with 375 additions and 151 deletions
|
@ -19,15 +19,15 @@ export default class CombinedInputElement<T, J, X> extends InputElement<X> {
|
|||
this._b = b;
|
||||
this._split = split;
|
||||
this._combined = new Combine([this._a, this._b]);
|
||||
this._value = this._a.GetValue().map(
|
||||
this._value = this._a.GetValue().sync(
|
||||
t => combine(t, this._b?.GetValue()?.data),
|
||||
[this._b.GetValue()],
|
||||
)
|
||||
.addCallback(x => {
|
||||
x => {
|
||||
const [t, j] = split(x)
|
||||
this._a.GetValue()?.setData(t)
|
||||
this._b.GetValue()?.setData(j)
|
||||
})
|
||||
return t
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
GetValue(): UIEventSource<X> {
|
||||
|
|
|
@ -3,6 +3,7 @@ import BaseUIElement from "../BaseUIElement";
|
|||
|
||||
export interface ReadonlyInputElement<T> extends BaseUIElement{
|
||||
GetValue(): Store<T>;
|
||||
IsValid(t: T): boolean;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import {Utils} from "../../Utils";
|
|||
|
||||
export class RadioButton<T> extends InputElement<T> {
|
||||
private static _nextId = 0;
|
||||
|
||||
private readonly value: UIEventSource<T>;
|
||||
private _elements: InputElement<T>[];
|
||||
private _selectFirstAsDefault: boolean;
|
||||
|
|
|
@ -11,7 +11,7 @@ export default class Toggle extends VariableUiElement {
|
|||
|
||||
public readonly isEnabled: Store<boolean>;
|
||||
|
||||
constructor(showEnabled: string | BaseUIElement, showDisabled: string | BaseUIElement, isEnabled: Store<boolean> = new UIEventSource<boolean>(false)) {
|
||||
constructor(showEnabled: string | BaseUIElement, showDisabled: string | BaseUIElement, isEnabled: Store<boolean>) {
|
||||
super(
|
||||
isEnabled?.map(isEnabled => isEnabled ? showEnabled : showDisabled)
|
||||
);
|
||||
|
|
|
@ -25,6 +25,7 @@ import Title from "../Base/Title";
|
|||
import InputElementMap from "./InputElementMap";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {Translation} from "../i18n/Translation";
|
||||
import BaseLayer from "../../Models/BaseLayer";
|
||||
|
||||
export class TextFieldDef {
|
||||
|
||||
|
@ -71,7 +72,7 @@ export class TextFieldDef {
|
|||
placeholder?: string | BaseUIElement,
|
||||
country?: () => string,
|
||||
location?: [number /*lat*/, number /*lon*/],
|
||||
mapBackgroundLayer?: UIEventSource<any>,
|
||||
mapBackgroundLayer?: UIEventSource</*BaseLayer*/ any>,
|
||||
unit?: Unit,
|
||||
args?: (string | number | boolean)[] // Extra arguments for the inputHelper,
|
||||
feature?: any,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {InputElement, ReadonlyInputElement} from "./InputElement";
|
||||
import {ReadonlyInputElement} from "./InputElement";
|
||||
import {Store} from "../../Logic/UIEventSource";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
|
@ -7,9 +7,9 @@ export default class VariableInputElement<T> extends BaseUIElement implements Re
|
|||
|
||||
private readonly value: Store<T>;
|
||||
private readonly element: BaseUIElement
|
||||
private readonly upstream: Store<InputElement<T>>;
|
||||
private readonly upstream: Store<ReadonlyInputElement<T>>;
|
||||
|
||||
constructor(upstream: Store<InputElement<T>>) {
|
||||
constructor(upstream: Store<ReadonlyInputElement<T>>) {
|
||||
super()
|
||||
this.upstream = upstream;
|
||||
this.value = upstream.bind(v => v.GetValue())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue