From 12fd59ff8d54e3b2d302cd47c601a08e18730ac8 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 13 Jun 2022 20:16:39 +0200 Subject: [PATCH] Fix search in filterViews --- Logic/UIEventSource.ts | 16 ++++++++++------ UI/BigComponents/FilterView.ts | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index 522878277..479940aa1 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -291,10 +291,14 @@ export class ImmutableStore extends Store { } - map(f: (t: T) => J): ImmutableStore { + map(f: (t: T) => J, extraStores: Store[] = undefined): ImmutableStore { + if(extraStores?.length > 0){ + return new MappedStore(this, f, extraStores, undefined, f(this.data)) + } return new ImmutableStore(f(this.data)); } + } /** @@ -367,7 +371,7 @@ class ListenerTracker { class MappedStore extends Store { private _upstream: Store; - private _upstreamCallbackHandler: ListenerTracker; + private _upstreamCallbackHandler: ListenerTracker | undefined; private _upstreamPingCount: number = -1; private _unregisterFromUpstream: (() => void) @@ -381,13 +385,13 @@ class MappedStore extends Store { constructor(upstream: Store, f: (t: TIn) => T, extraStores: Store[], - upstreamListenerHandler: ListenerTracker, initialState: T) { + upstreamListenerHandler: ListenerTracker | undefined, initialState: T) { super(); this._upstream = upstream; this._upstreamCallbackHandler = upstreamListenerHandler this._f = f; this._data = initialState - this._upstreamPingCount = upstreamListenerHandler.pingCount + this._upstreamPingCount = upstreamListenerHandler?.pingCount this._extraStores = extraStores; this.registerCallbacksToUpstream() } @@ -407,7 +411,7 @@ class MappedStore extends Store { get data(): T { if (!this._callbacksAreRegistered) { // Callbacks are not registered, so we haven't been listening for updates from the upstream which might have changed - if(this._upstreamCallbackHandler.pingCount != this._upstreamPingCount){ + if(this._upstreamCallbackHandler?.pingCount != this._upstreamPingCount){ // Upstream has pinged - let's update our data first this._data = this._f(this._upstream.data) } @@ -462,7 +466,7 @@ class MappedStore extends Store { private update(): void { const newData = this._f(this._upstream.data) - this._upstreamPingCount = this._upstreamCallbackHandler.pingCount + this._upstreamPingCount = this._upstreamCallbackHandler?.pingCount if (this._data == newData) { return; } diff --git a/UI/BigComponents/FilterView.ts b/UI/BigComponents/FilterView.ts index 4eb75f271..94e6b7d97 100644 --- a/UI/BigComponents/FilterView.ts +++ b/UI/BigComponents/FilterView.ts @@ -226,6 +226,10 @@ export default class FilterView extends VariableUiElement { const settableFilter = new UIEventSource(undefined) trigger.addCallbackAndRun(state => settableFilter.setData(state)) settableFilter.addCallback(state => { + if(state === undefined){ + // still initializing + return + } if(state.currentFilter === undefined){ allFields.forEach(f => f.GetValue().setData(undefined)); }