forked from MapComplete/MapComplete
		
	Fix search in filterViews
This commit is contained in:
		
							parent
							
								
									a4916a9b6d
								
							
						
					
					
						commit
						12fd59ff8d
					
				
					 2 changed files with 14 additions and 6 deletions
				
			
		| 
						 | 
					@ -291,10 +291,14 @@ export class ImmutableStore<T> extends Store<T> {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    map<J>(f: (t: T) => J): ImmutableStore<J> {
 | 
					    map<J>(f: (t: T) => J, extraStores: Store<any>[] = undefined): ImmutableStore<J> {
 | 
				
			||||||
 | 
					        if(extraStores?.length > 0){
 | 
				
			||||||
 | 
					            return new MappedStore(this, f, extraStores, undefined, f(this.data))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return new ImmutableStore<J>(f(this.data));
 | 
					        return new ImmutableStore<J>(f(this.data));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -367,7 +371,7 @@ class ListenerTracker<T> {
 | 
				
			||||||
class MappedStore<TIn, T> extends Store<T> {
 | 
					class MappedStore<TIn, T> extends Store<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private _upstream: Store<TIn>;
 | 
					    private _upstream: Store<TIn>;
 | 
				
			||||||
    private _upstreamCallbackHandler: ListenerTracker<TIn>;
 | 
					    private _upstreamCallbackHandler: ListenerTracker<TIn> | undefined;
 | 
				
			||||||
    private _upstreamPingCount: number = -1;
 | 
					    private _upstreamPingCount: number = -1;
 | 
				
			||||||
    private _unregisterFromUpstream: (() => void)
 | 
					    private _unregisterFromUpstream: (() => void)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					@ -381,13 +385,13 @@ class MappedStore<TIn, T> extends Store<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(upstream: Store<TIn>, f: (t: TIn) => T, extraStores: Store<any>[], 
 | 
					    constructor(upstream: Store<TIn>, f: (t: TIn) => T, extraStores: Store<any>[], 
 | 
				
			||||||
                upstreamListenerHandler: ListenerTracker<TIn>, initialState: T) {
 | 
					                upstreamListenerHandler: ListenerTracker<TIn> | undefined, initialState: T) {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
        this._upstream = upstream;
 | 
					        this._upstream = upstream;
 | 
				
			||||||
        this._upstreamCallbackHandler = upstreamListenerHandler
 | 
					        this._upstreamCallbackHandler = upstreamListenerHandler
 | 
				
			||||||
        this._f = f;
 | 
					        this._f = f;
 | 
				
			||||||
        this._data = initialState
 | 
					        this._data = initialState
 | 
				
			||||||
        this._upstreamPingCount = upstreamListenerHandler.pingCount
 | 
					        this._upstreamPingCount = upstreamListenerHandler?.pingCount
 | 
				
			||||||
        this._extraStores = extraStores;
 | 
					        this._extraStores = extraStores;
 | 
				
			||||||
        this.registerCallbacksToUpstream()
 | 
					        this.registerCallbacksToUpstream()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -407,7 +411,7 @@ class MappedStore<TIn, T> extends Store<T> {
 | 
				
			||||||
    get data(): T { 
 | 
					    get data(): T { 
 | 
				
			||||||
        if (!this._callbacksAreRegistered) {
 | 
					        if (!this._callbacksAreRegistered) {
 | 
				
			||||||
            // Callbacks are not registered, so we haven't been listening for updates from the upstream which might have changed
 | 
					            // 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
 | 
					                // Upstream has pinged - let's update our data first
 | 
				
			||||||
                this._data = this._f(this._upstream.data)
 | 
					                this._data = this._f(this._upstream.data)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -462,7 +466,7 @@ class MappedStore<TIn, T> extends Store<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private update(): void {
 | 
					    private update(): void {
 | 
				
			||||||
        const newData = this._f(this._upstream.data)
 | 
					        const newData = this._f(this._upstream.data)
 | 
				
			||||||
        this._upstreamPingCount = this._upstreamCallbackHandler.pingCount
 | 
					        this._upstreamPingCount = this._upstreamCallbackHandler?.pingCount
 | 
				
			||||||
        if (this._data == newData) {
 | 
					        if (this._data == newData) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -226,6 +226,10 @@ export default class FilterView extends VariableUiElement {
 | 
				
			||||||
        const settableFilter = new UIEventSource<FilterState>(undefined)
 | 
					        const settableFilter = new UIEventSource<FilterState>(undefined)
 | 
				
			||||||
        trigger.addCallbackAndRun(state => settableFilter.setData(state))
 | 
					        trigger.addCallbackAndRun(state => settableFilter.setData(state))
 | 
				
			||||||
        settableFilter.addCallback(state => {
 | 
					        settableFilter.addCallback(state => {
 | 
				
			||||||
 | 
					            if(state === undefined){
 | 
				
			||||||
 | 
					                // still initializing
 | 
				
			||||||
 | 
					                return
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if(state.currentFilter === undefined){
 | 
					            if(state.currentFilter === undefined){
 | 
				
			||||||
                allFields.forEach(f => f.GetValue().setData(undefined));
 | 
					                allFields.forEach(f => f.GetValue().setData(undefined));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue