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

@ -18,7 +18,7 @@ export default class LazyElement extends UIElement {
}
self.Update();
// @ts-ignore
if(this._content.Activate){
if (this._content.Activate) {
// THis is ugly - I know
// @ts-ignore
this._content.Activate();

View file

@ -8,6 +8,7 @@ import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
import {Utils} from "../../Utils";
export default class FeatureInfoBox extends ScrollableFullScreen {
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 {
let innerMap = FeatureInfoBox.featureInfoboxCache.get(layer);
if (innerMap === undefined) {
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;
let innerMap = Utils.getOrSetDefault(FeatureInfoBox.featureInfoboxCache, layer,() => new Map<UIEventSource<any>, FeatureInfoBox>())
return Utils.getOrSetDefault(innerMap, tags, () => new FeatureInfoBox(tags, layer));
}
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 {Review} from "../../Logic/Web/Review";

View file

@ -8,7 +8,7 @@ export class Utils {
* This is a workaround and yet another hack
*/
public static runningFromConsole = false;
public static readonly assets_path = "./assets/svg/";
static EncodeXmlValue(str) {
@ -46,7 +46,7 @@ export class Utils {
}
public static Round(i: number) {
if(i < 0){
if (i < 0) {
return "-" + Utils.Round(-i);
}
const j = "" + Math.floor(i * 10);
@ -86,8 +86,8 @@ export class Utils {
}
return ls;
}
public static NoEmpty(array: string[]): string[]{
public static NoEmpty(array: string[]): string[] {
const ls: string[] = [];
for (const t of array) {
if (t === "") {
@ -98,18 +98,18 @@ export class Utils {
return ls;
}
public static EllipsesAfter(str : string, l : number = 100){
if(str === undefined){
public static EllipsesAfter(str: string, l: number = 100) {
if (str === undefined) {
return undefined;
}
if(str.length <= l){
if (str.length <= l) {
return str;
}
return str.substr(0, l - 3)+"...";
return str.substr(0, l - 3) + "...";
}
public static Dedup(arr: string[]):string[]{
if(arr === undefined){
public static Dedup(arr: string[]): string[] {
if (arr === undefined) {
return undefined;
}
const newArr = [];
@ -141,7 +141,7 @@ export class Utils {
}
// Date will be undefined on failure
public static LoadCustomCss(location: string){
public static LoadCustomCss(location: string) {
const head = document.getElementsByTagName('head')[0];
const link = document.createElement('link');
link.id = "customCss";
@ -150,26 +150,37 @@ export class Utils {
link.href = location;
link.media = 'all';
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));
source = JSON.parse(JSON.stringify(source));
for (const key in source) {
const sourceV = source[key];
const targetV = target[key]
if(typeof sourceV === "object"){
if(targetV === undefined){
if (typeof sourceV === "object") {
if (targetV === undefined) {
target[key] = sourceV;
}else{
} else {
Utils.Merge(sourceV, targetV);
}
}else{
} else {
target[key] = sourceV;
}
}
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);
}
}