React to sequence change notifications in SequenceList

This commit is contained in:
D. Berge
2020-10-02 16:33:06 +02:00
parent cf1678ed25
commit e8c230ccc2

View File

@@ -377,12 +377,13 @@ export default {
options: {},
num_rows: null,
activeItem: null,
edit: null // {sequence, key, value}
edit: null, // {sequence, key, value}
queuedReload: false
}
},
computed: {
...mapGetters(['loading'])
...mapGetters(['loading', 'serverEvent'])
},
watch: {
@@ -404,7 +405,35 @@ export default {
}
}
}
},
async serverEvent (event) {
const subscriptions = ["raw_lines", "final_lines"];
if (subscriptions.includes(event.channel) && event.payload.pid == this.$route.params.project) {
if (!this.loading && !this.queuedReload) {
// Do not force a non-cached response if refreshing as a result
// of an event notification. We will assume that the server has
// already had time to update the cache by the time our request
// gets back to it.
this.getSequences();
} else {
this.queuedReload = true;
}
}
},
queuedReload (newVal, oldVal) {
if (newVal && !oldVal && !this.loading) {
this.getSequences();
}
},
loading (newVal, oldVal) {
if (!newVal && oldVal && this.queuedReload) {
this.getSequences();
}
}
},
methods: {
@@ -458,6 +487,7 @@ export default {
}
const url = `/project/${this.$route.params.project}/sequence?${query.toString()}`;
this.queuedReload = false;
this.items = await this.api([url]) || [];
},