Add notification handlers to Map.

They reload any sequence data on notification of changes.
This commit is contained in:
D. Berge
2025-08-08 12:45:15 +02:00
parent 6a5238496e
commit 08dfe7ef0a

View File

@@ -1310,6 +1310,55 @@ export default {
return arr.buffer;
},
async handleSequences (context, {payload}) {
if (payload.pid != this.$route.params.project) {
console.warn(`${this.$route.params.project} ignoring notification for ${payload.pid}`);
return;
}
console.log("handleSequences (Map)", payload);
if (payload.old?.sequence) {
console.log(`Remove sequence ${payload.old.sequence} from data`);
this.sequenceDataElements = this.sequenceDataElements.filter( el => el.sequence != payload.old.sequence );
if (window.caches) {
const cache = await caches.open("dougal");
const rx = new RegExp(`/project/${this.$route.params.project}/sequence/${payload.old.sequence}(\\?.*)?$`);
const keys = await cache.keys();
for (const req of keys) {
if (rx.test(req.url)) {
console.log(`Removing ${req.url} from cache`);
cache.delete(req);
}
}
}
}
if (payload.new?.sequence) {
console.log(`Add sequence ${payload.new.sequence} to data`);
this.getSequenceData([payload.new.sequence]);
}
},
registerNotificationHandlers (action = "registerHandler") {
["raw_lines", "raw_shots", "final_lines", "final_shots"].forEach( table => {
this.$store.dispatch(action, {
table,
handler: (context, message) => {
this.handleSequences(context, message);
}
})
});
},
unregisterNotificationHandlers () {
this.registerNotificationHandlers("unregisterHandler");
},
...mapActions(["api"])
},
@@ -1403,8 +1452,14 @@ export default {
this.isFullscreen = !!document.fullscreenElement;
});
this.registerNotificationHandlers();
//this.layerSelection = [ "seq" ];
this.getSequenceData();
},
beforeDestroy () {
this.unregisterNotificationHandlers();
}
}