forked from MapComplete/MapComplete
Fix broken variableInputElement
This commit is contained in:
parent
2979abdfcd
commit
36ac99c9ec
2 changed files with 36 additions and 9 deletions
|
@ -383,13 +383,13 @@ class MappedStore<TIn, T> extends Store<T> {
|
|||
private static readonly pass: () => {}
|
||||
|
||||
|
||||
constructor(upstream: Store<TIn>, f: (t: TIn) => T, extraStores: Store<any>[] = undefined,
|
||||
upstreamListenerHandler: ListenerTracker<TIn>) {
|
||||
constructor(upstream: Store<TIn>, f: (t: TIn) => T, extraStores: Store<any>[],
|
||||
upstreamListenerHandler: ListenerTracker<TIn>, initialState: T) {
|
||||
super();
|
||||
this._upstream = upstream;
|
||||
this._upstreamCallbackHandler = upstreamListenerHandler
|
||||
this._f = f;
|
||||
this._data = f(upstream.data)
|
||||
this._data = initialState
|
||||
this._upstreamPingCount = upstreamListenerHandler.pingCount
|
||||
this._extraStores = extraStores;
|
||||
this.registerCallbacksToUpstream()
|
||||
|
@ -436,10 +436,11 @@ class MappedStore<TIn, T> extends Store<T> {
|
|||
})
|
||||
}
|
||||
return new MappedStore(
|
||||
this._upstream,
|
||||
data => f(this._f(data)),
|
||||
this,
|
||||
f, // we could fuse the functions here (e.g. data => f(this._f(data), but this might result in _f being calculated multiple times, breaking things
|
||||
stores,
|
||||
this._upstreamCallbackHandler
|
||||
this._callbacks,
|
||||
f(this.data)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -669,7 +670,7 @@ export class UIEventSource<T> extends Store<T> {
|
|||
*/
|
||||
public map<J>(f: ((t: T) => J),
|
||||
extraSources: Store<any>[] = []): Store<J> {
|
||||
return new MappedStore(this, f, extraSources, this._callbacks);
|
||||
return new MappedStore(this, f, extraSources, this._callbacks, f(this.data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
30
test.ts
30
test.ts
|
@ -1,6 +1,11 @@
|
|||
import {UIEventSource} from "./Logic/UIEventSource";
|
||||
import TagRenderingQuestion from "./UI/Popup/TagRenderingQuestion";
|
||||
import TagRenderingConfig from "./Models/ThemeConfig/TagRenderingConfig";
|
||||
import {RadioButton} from "./UI/Input/RadioButton";
|
||||
import {FixedInputElement} from "./UI/Input/FixedInputElement";
|
||||
import {VariableUiElement} from "./UI/Base/VariableUIElement";
|
||||
import ValidatedTextField from "./UI/Input/ValidatedTextField";
|
||||
import VariableInputElement from "./UI/Input/VariableInputElement";
|
||||
|
||||
const config = new TagRenderingConfig({
|
||||
question: "What is the name?",
|
||||
|
@ -21,5 +26,26 @@ const tags = new UIEventSource<any>({
|
|||
name: "current feature name"
|
||||
})
|
||||
|
||||
new TagRenderingQuestion(
|
||||
tags, config, undefined).AttachTo("maindiv")
|
||||
/*new TagRenderingQuestion(
|
||||
tags, config, undefined).AttachTo("maindiv")*/
|
||||
const options = new UIEventSource<string[]>([])
|
||||
const rb =
|
||||
new VariableInputElement(
|
||||
options.map(options => {
|
||||
console.trace("Construction an input element for", options)
|
||||
return new RadioButton(
|
||||
[
|
||||
...options.map(o => new FixedInputElement(o,o)),
|
||||
new FixedInputElement<string>("abc", "abc"),
|
||||
ValidatedTextField.ForType().ConstructInputElement()
|
||||
])
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
rb.AttachTo("maindiv")
|
||||
rb.GetValue().addCallbackAndRun(v => console.log("Current value is",v))
|
||||
new VariableUiElement(rb.GetValue()).AttachTo("extradiv")
|
||||
|
||||
window.setTimeout(() => {options.setData(["xyz","foo","bar"])},10000)
|
Loading…
Reference in a new issue