diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index 5fbfdcda6..c2ecc0c25 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -383,13 +383,13 @@ class MappedStore extends Store { private static readonly pass: () => {} - constructor(upstream: Store, f: (t: TIn) => T, extraStores: Store[] = undefined, - upstreamListenerHandler: ListenerTracker) { + constructor(upstream: Store, f: (t: TIn) => T, extraStores: Store[], + upstreamListenerHandler: ListenerTracker, 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 extends Store { }) } 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 extends Store { */ public map(f: ((t: T) => J), extraSources: Store[] = []): Store { - return new MappedStore(this, f, extraSources, this._callbacks); + return new MappedStore(this, f, extraSources, this._callbacks, f(this.data)); } /** diff --git a/test.ts b/test.ts index a48df7091..885ca13c3 100644 --- a/test.ts +++ b/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({ name: "current feature name" }) -new TagRenderingQuestion( - tags, config, undefined).AttachTo("maindiv") \ No newline at end of file +/*new TagRenderingQuestion( + tags, config, undefined).AttachTo("maindiv")*/ +const options = new UIEventSource([]) +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("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) \ No newline at end of file