import { FeatureSource } from "../FeatureSource" import { Feature } from "geojson" import { Store, UIEventSource } from "../../UIEventSource" export class IfVisibleFeatureSource implements FeatureSource { private readonly _features: UIEventSource = new UIEventSource([]) public readonly features: Store = this._features constructor(upstream: FeatureSource, visible: Store) { let dirty = false upstream.features.addCallbackAndRun(features => { if (!visible.data) { dirty = true this._features.set([]) return } this._features.set(features) dirty = false }) visible.addCallbackAndRun(isVisible => { if (isVisible && dirty) { this._features.set(upstream.features.data) dirty = false } if (!visible) { this._features.set([]) } }) } }