Small code cleanups, documentation

This commit is contained in:
pietervdvn 2021-03-09 13:10:48 +01:00
parent cb42a4fcc5
commit 085d762bff
4 changed files with 37 additions and 34 deletions

View file

@ -8,6 +8,7 @@ import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State"; import State from "../../State";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig"; import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import ScrollableFullScreen from "../Base/ScrollableFullScreen"; import ScrollableFullScreen from "../Base/ScrollableFullScreen";
import {Utils} from "../../Utils";
export default class FeatureInfoBox extends ScrollableFullScreen { export default class FeatureInfoBox extends ScrollableFullScreen {
private static featureInfoboxCache: Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>> = new Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>>(); private static featureInfoboxCache: Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>> = new Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>>();
@ -24,18 +25,8 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
} }
static construct(tags: UIEventSource<any>, layer: LayerConfig): FeatureInfoBox { static construct(tags: UIEventSource<any>, layer: LayerConfig): FeatureInfoBox {
let innerMap = FeatureInfoBox.featureInfoboxCache.get(layer); let innerMap = Utils.getOrSetDefault(FeatureInfoBox.featureInfoboxCache, layer,() => new Map<UIEventSource<any>, FeatureInfoBox>())
if (innerMap === undefined) { return Utils.getOrSetDefault(innerMap, tags, () => new FeatureInfoBox(tags, layer));
innerMap = new Map<UIEventSource<any>, FeatureInfoBox>();
FeatureInfoBox.featureInfoboxCache.set(layer, innerMap);
}
let featureInfoBox = innerMap.get(tags);
if (featureInfoBox === undefined) {
featureInfoBox = new FeatureInfoBox(tags, layer);
innerMap.set(tags, featureInfoBox);
}
return featureInfoBox;
} }
private static GenerateTitleBar(tags: UIEventSource<any>, private static GenerateTitleBar(tags: UIEventSource<any>,

View file

@ -1,5 +1,6 @@
/** /**
* Shows the reviews and scoring base on mangrove.reviesw * Shows the reviews and scoring base on mangrove.reviews
* The middle element is some other component shown in the middle, e.g. the review input element
*/ */
import {UIEventSource} from "../../Logic/UIEventSource"; import {UIEventSource} from "../../Logic/UIEventSource";
import {Review} from "../../Logic/Web/Review"; import {Review} from "../../Logic/Web/Review";

View file

@ -152,6 +152,7 @@ export class Utils {
head.appendChild(link); head.appendChild(link);
console.log("Added custom layout ", location) console.log("Added custom layout ", location)
} }
static Merge(source: any, target: any) { static Merge(source: any, target: any) {
target = JSON.parse(JSON.stringify(target)); target = JSON.parse(JSON.stringify(target));
source = JSON.parse(JSON.stringify(source)); source = JSON.parse(JSON.stringify(source));
@ -172,4 +173,14 @@ export class Utils {
} }
return target; return target;
} }
static getOrSetDefault<K, V>(dict: Map<K, V>, k: K, v: () => V) {
let found = dict.get(k);
if (found !== undefined) {
return found;
}
dict.set(k, v());
return dict.get(k);
}
} }