Fix stacked updates
This commit is contained in:
parent
85cefa1b7b
commit
6a284e9b6b
@ -62,6 +62,12 @@
|
||||
|
||||
import Autocomplete from './Autocomplete.vue';
|
||||
|
||||
function clearTimeouts(timers) {
|
||||
if(timers.length > 1) console.warn('Clearing multiple timeouts', timers.slice());
|
||||
for(var i = 0; i < timers.length; ++i) window.clearTimeout(timers[i]);
|
||||
timers.length = 0;
|
||||
}
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Autocomplete
|
||||
@ -78,6 +84,7 @@
|
||||
data() {
|
||||
return {
|
||||
appointments: [],
|
||||
timers: [],
|
||||
ts: null,
|
||||
age: undefined,
|
||||
filter: {}
|
||||
@ -118,16 +125,17 @@
|
||||
return true;
|
||||
},
|
||||
async update() {
|
||||
clearTimeouts(this.timers);
|
||||
try {
|
||||
this.appointments = (await this.client.SDEC_CRSCHED(this.selection.join('|') + '|', strfdate_vista(this.date_begin), strfdate_vista(this.date_end) + '@2359')).sort((a, b) => (new Date(a.START_TIME)) - (new Date(b.START_TIME)));
|
||||
var now = new Date();
|
||||
this.ts = this.appointments._ts ? new Date(1000*this.appointments._ts) : now;
|
||||
this.age = now - this.ts;
|
||||
this.timer = window.setTimeout(this.update, Math.max(60000 - this.age, 10000));
|
||||
this.timers.push(window.setTimeout(this.update, Math.max(60000 - this.age, 10000)));
|
||||
} catch(ex) {
|
||||
this.age = this.ts ? (new Date()) - this.ts : Infinity;
|
||||
console.warn(ex);
|
||||
this.timer = window.setTimeout(this.update, 30000);
|
||||
this.timers.push(window.setTimeout(this.update, 30000));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -136,13 +144,12 @@
|
||||
() => (this.client, this.selection, this.date_begin, this.date_end, {}),
|
||||
debounce(async () => {
|
||||
this.filter = {};
|
||||
window.clearTimeout(this.timer);
|
||||
this.update();
|
||||
}, 500)
|
||||
);
|
||||
},
|
||||
unmounted() {
|
||||
window.clearTimeout(this.timer);
|
||||
clearTimeouts(this.timers);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user