Full code cleanup

This commit is contained in:
Pieter Vander Vennet 2022-01-26 21:40:38 +01:00
parent 3a4a2a2016
commit fa971ffbbf
300 changed files with 16352 additions and 19284 deletions

View file

@ -14,6 +14,7 @@ export default class MetaTagging {
private static errorPrintCount = 0;
private static readonly stopErrorOutputAt = 10;
private static retaggingFuncCache = new Map<string, ((feature: any) => void)[]>()
/**
* This method (re)calculates all metatags and calculated tags on every given object.
@ -24,7 +25,7 @@ export default class MetaTagging {
public static addMetatags(features: { feature: any; freshness: Date }[],
params: ExtraFuncParams,
layer: LayerConfig,
state?: {allElements?: ElementStorage},
state?: { allElements?: ElementStorage },
options?: {
includeDates?: true | boolean,
includeNonDates?: true | boolean
@ -56,7 +57,7 @@ export default class MetaTagging {
const feature = ff.feature
const freshness = ff.freshness
let somethingChanged = false
let definedTags = new Set(Object.getOwnPropertyNames( feature.properties ))
let definedTags = new Set(Object.getOwnPropertyNames(feature.properties))
for (const metatag of metatagsToApply) {
try {
if (!metatag.keys.some(key => feature.properties[key] === undefined)) {
@ -65,7 +66,7 @@ export default class MetaTagging {
}
if (metatag.isLazy) {
if(!metatag.keys.some(key => !definedTags.has(key))) {
if (!metatag.keys.some(key => !definedTags.has(key))) {
// All keys are defined - lets skip!
continue
}
@ -104,7 +105,7 @@ export default class MetaTagging {
}
return atLeastOneFeatureChanged
}
private static createFunctionsForFeature(layerId: string, calculatedTags: [string, string, boolean][]): ((feature: any) => void)[] {
const functions: ((feature: any) => any)[] = [];
for (const entry of calculatedTags) {
@ -128,7 +129,7 @@ export default class MetaTagging {
delete feat.properties[key]
feat.properties[key] = result;
return result
}catch(e){
} catch (e) {
if (MetaTagging.errorPrintCount < MetaTagging.stopErrorOutputAt) {
console.warn("Could not calculate a " + (isStrict ? "strict " : "") + " calculated tag for key " + key + " defined by " + code + " (in layer" + layerId + ") due to \n" + e + "\n. Are you the theme creator? Doublecheck your code. Note that the metatags might not be stable on new features", e, e.stack)
MetaTagging.errorPrintCount++;
@ -138,10 +139,10 @@ export default class MetaTagging {
}
return undefined;
}
}
if(isStrict){
}
if (isStrict) {
functions.push(calculateAndAssign)
continue
}
@ -166,8 +167,6 @@ export default class MetaTagging {
return functions;
}
private static retaggingFuncCache = new Map<string, ((feature: any) => void)[]>()
/**
* Creates the function which adds all the calculated tags to a feature. Called once per layer
* @param layer
@ -182,7 +181,7 @@ export default class MetaTagging {
return undefined;
}
let functions :((feature: any) => void)[] = MetaTagging.retaggingFuncCache.get(layer.id);
let functions: ((feature: any) => void)[] = MetaTagging.retaggingFuncCache.get(layer.id);
if (functions === undefined) {
functions = MetaTagging.createFunctionsForFeature(layer.id, calculatedTags)
MetaTagging.retaggingFuncCache.set(layer.id, functions)