mapcomplete/Logic/Actors/ChangeToElementsActor.ts

35 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-09-08 21:40:48 +02:00
import { ElementStorage } from "../ElementStorage"
import { Changes } from "../Osm/Changes"
export default class ChangeToElementsActor {
constructor(changes: Changes, allElements: ElementStorage) {
2022-09-08 21:40:48 +02:00
changes.pendingChanges.addCallbackAndRun((changes) => {
for (const change of changes) {
2022-09-08 21:40:48 +02:00
const id = change.type + "/" + change.id
if (!allElements.has(id)) {
2022-09-08 21:40:48 +02:00
continue // Ignored as the geometryFixer will introduce this
}
const src = allElements.getEventSourceById(id)
2022-09-08 21:40:48 +02:00
let changed = false
for (const kv of change.tags ?? []) {
// Apply tag changes and ping the consumers
const k = kv.k
let v = kv.v
if (v === "") {
2022-09-08 21:40:48 +02:00
v = undefined
}
if (src.data[k] === v) {
continue
}
2022-09-08 21:40:48 +02:00
changed = true
src.data[k] = v
}
if (changed) {
src.ping()
}
}
})
}
2022-09-08 21:40:48 +02:00
}