forked from MapComplete/MapComplete
Better handling of metatags, more robust error handling when calculating tags
This commit is contained in:
parent
69363fbf0f
commit
6ac8a5373c
10 changed files with 134 additions and 89 deletions
|
@ -32,7 +32,19 @@ export class ElementStorage {
|
|||
return es;
|
||||
}
|
||||
|
||||
addOrGetById(elementId: string, newProperties: any): UIEventSource<any> {
|
||||
getEventSourceById(elementId): UIEventSource<any> {
|
||||
if (this._elements.has(elementId)) {
|
||||
return this._elements.get(elementId);
|
||||
}
|
||||
console.error("Can not find eventsource with id ", elementId);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
has(id) {
|
||||
return this._elements.has(id);
|
||||
}
|
||||
|
||||
private addOrGetById(elementId: string, newProperties: any): UIEventSource<any> {
|
||||
if (!this._elements.has(elementId)) {
|
||||
const eventSource = new UIEventSource<any>(newProperties, "tags of " + elementId);
|
||||
this._elements.set(elementId, eventSource);
|
||||
|
@ -48,30 +60,33 @@ export class ElementStorage {
|
|||
const keptKeys = es.data;
|
||||
// The element already exists
|
||||
// We use the new feature to overwrite all the properties in the already existing eventsource
|
||||
console.log("Merging multiple instances of ", elementId)
|
||||
const debug_msg = []
|
||||
let somethingChanged = false;
|
||||
for (const k in newProperties) {
|
||||
const v = newProperties[k];
|
||||
|
||||
if (keptKeys[k] !== v) {
|
||||
keptKeys[k] = v;
|
||||
|
||||
if (v === undefined) {
|
||||
// The new value is undefined; the tag might have been removed
|
||||
// It might be a metatag as well
|
||||
// In the latter case, we do keep the tag!
|
||||
if (!k.startsWith("_")) {
|
||||
delete keptKeys[k]
|
||||
debug_msg.push(("Erased " + k))
|
||||
}
|
||||
} else {
|
||||
keptKeys[k] = v;
|
||||
debug_msg.push(k + " --> " + v)
|
||||
}
|
||||
|
||||
somethingChanged = true;
|
||||
}
|
||||
}
|
||||
if (somethingChanged) {
|
||||
console.trace(`Merging multiple instances of ${elementId}: ` + debug_msg.join(", ")+" newProperties: ", newProperties)
|
||||
es.ping();
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
getEventSourceById(elementId): UIEventSource<any> {
|
||||
if (this._elements.has(elementId)) {
|
||||
return this._elements.get(elementId);
|
||||
}
|
||||
console.error("Can not find eventsource with id ", elementId);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
has(id) {
|
||||
return this._elements.has(id);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue