Add flag to generate new items only once

This commit is contained in:
pietervdvn 2021-07-18 17:50:35 +02:00
parent 9c9be0918b
commit 9f91d30147
2 changed files with 47 additions and 46 deletions

View file

@ -13,7 +13,9 @@ export default class ChangeApplicator implements FeatureSource {
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]>;
public readonly name: string;
constructor(source: FeatureSource, changes: Changes) {
constructor(source: FeatureSource, changes: Changes, mode?: {
generateNewGeometries: boolean
}) {
this.name = "ChangesApplied(" + source.name + ")"
this.features = source.features
@ -21,10 +23,10 @@ export default class ChangeApplicator implements FeatureSource {
const self = this;
let runningUpdate = false;
source.features.addCallbackAndRunD(features => {
if(runningUpdate){
if (runningUpdate) {
return; // No need to ping again
}
ChangeApplicator.ApplyChanges(features, changes.pendingChanges.data)
ChangeApplicator.ApplyChanges(features, changes.pendingChanges.data, mode)
seenChanges.clear()
})
@ -33,7 +35,7 @@ export default class ChangeApplicator implements FeatureSource {
changes = changes.filter(ch => !seenChanges.has(ch))
changes.forEach(c => seenChanges.add(c))
console.log("Called back", changes)
ChangeApplicator.ApplyChanges(self.features.data, changes)
ChangeApplicator.ApplyChanges(self.features.data, changes, mode)
source.features.ping()
runningUpdate = false;
})
@ -45,9 +47,9 @@ export default class ChangeApplicator implements FeatureSource {
/**
* Returns true if the geometry is changed and the source should be pinged
*/
private static ApplyChanges(features: {feature: any, freshness: Date}[], cs: ChangeDescription[]): boolean {
if (cs.length === 0 || features === undefined ) {
return ;
private static ApplyChanges(features: { feature: any; freshness: Date }[], cs: ChangeDescription[], mode: { generateNewGeometries: boolean }): boolean {
if (cs.length === 0 || features === undefined) {
return;
}
console.log("Applying changes ", this.name, cs)
@ -75,13 +77,15 @@ export default class ChangeApplicator implements FeatureSource {
// First, create the new features - they have a negative ID
// We don't set the properties yet though
if (mode?.generateNewGeometries) {
changesPerId.forEach(cs => {
cs.forEach(change => {
cs
.forEach(change => {
if (change.id >= 0) {
return; // Nothing to do here, already created
}
if(change.changes === undefined){
if (change.changes === undefined) {
// An update to the object - not the actual created
return;
}
@ -113,7 +117,7 @@ export default class ChangeApplicator implements FeatureSource {
}
})
})
}
for (const feature of features) {
const f = feature.feature;
@ -133,9 +137,6 @@ export default class ChangeApplicator implements FeatureSource {
// Apply tag changes and ping the consumers
const k = kv.k
let v = kv.v
if (v === "") {
v = undefined;
}
f.properties[k] = v;
}

View file

@ -43,7 +43,7 @@ export default class FeaturePipeline implements FeatureSource {
new FeatureDuplicatorPerLayer(flayers,
new RegisteringFeatureSource(
new ChangeApplicator(
updater, changes
updater, changes, {generateNewGeometries: true}
))
)), layout));