Don't use unnecessary promises

This commit is contained in:
Antoine Bartuccio 2024-08-17 10:15:13 +02:00
parent 8865529b39
commit 759e360a1d

View File

@ -163,18 +163,16 @@
async init() { async init() {
this.update = Alpine.debounce(async () => { this.update = Alpine.debounce(async () => {
await Promise.all(this.to_change).then(async (data) => {
{# Create the whole url before changing everything all at once #} {# Create the whole url before changing everything all at once #}
let first = data.shift(); let first = this.to_change.shift();
let url = update_query_string(first[0], first[1], History.NONE); let url = update_query_string(first.param, first.value, History.NONE);
data.forEach((data) => { this.to_change.forEach((value) => {
url = update_query_string(data[0], data[1], History.NONE, url); url = update_query_string(value.param, value.value, History.NONE, url);
}) })
update_query_string(first[0], first[1], this.pushstate, url); update_query_string(first.param, first.value, this.pushstate, url);
await this.fetch_data(); {# reload data on form change #} await this.fetch_data(); {# reload data on form change #}
this.to_change = []; this.to_change = [];
this.pushstate = History.PUSH; this.pushstate = History.PUSH;
})
}, 50); }, 50);
let search_params = ["search", "department", "credit_type", "semester"]; let search_params = ["search", "department", "credit_type", "semester"];
@ -193,10 +191,7 @@
}); });
search_params.concat(pagination_params).forEach((param) => { search_params.concat(pagination_params).forEach((param) => {
this.$watch(param, async (value) => { this.$watch(param, async (value) => {
this.to_change.push(new Promise((resolve) => { this.to_change.push({ param: param, value: value })
resolve([param, value]);
})
);
this.update(); this.update();
}); });
}); });