Avoid update races
This commit is contained in:
parent
af8b05d20c
commit
70c7e0b0f3
@ -6,6 +6,8 @@ import {_, localize} from "../lib/i18n";
|
|||||||
import {Prefs} from "../lib/prefs";
|
import {Prefs} from "../lib/prefs";
|
||||||
import PORT from "./manager/port";
|
import PORT from "./manager/port";
|
||||||
import { runtime } from "../lib/browser";
|
import { runtime } from "../lib/browser";
|
||||||
|
import { Promised } from "../lib/util";
|
||||||
|
import { PromiseSerializer } from "../lib/pserializer";
|
||||||
|
|
||||||
const $ = document.querySelector.bind(document);
|
const $ = document.querySelector.bind(document);
|
||||||
|
|
||||||
@ -67,7 +69,9 @@ addEventListener("DOMContentLoaded", function dom() {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
const tabled = new Promised();
|
||||||
const loaded = Promise.all([LOADED, platformed]);
|
const loaded = Promise.all([LOADED, platformed]);
|
||||||
|
const fullyloaded = Promise.all([LOADED, platformed, tabled]);
|
||||||
|
|
||||||
localize(document.documentElement);
|
localize(document.documentElement);
|
||||||
$("#donate").addEventListener("click", () => {
|
$("#donate").addEventListener("click", () => {
|
||||||
@ -85,18 +89,22 @@ addEventListener("DOMContentLoaded", function dom() {
|
|||||||
Table.init();
|
Table.init();
|
||||||
const loading = $("#loading");
|
const loading = $("#loading");
|
||||||
loading.parentElement.removeChild(loading);
|
loading.parentElement.removeChild(loading);
|
||||||
|
tabled.resolve();
|
||||||
}
|
}
|
||||||
Table.setItems(items);
|
Table.setItems(items);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
PORT.on("dirty", async items => {
|
|
||||||
await loaded;
|
// Updates
|
||||||
|
const serializer = new PromiseSerializer(1);
|
||||||
|
PORT.on("dirty", serializer.wrap(this, async (items: any[]) => {
|
||||||
|
await fullyloaded;
|
||||||
Table.updateItems(items);
|
Table.updateItems(items);
|
||||||
});
|
}));
|
||||||
PORT.on("removed", async sids => {
|
PORT.on("removed", serializer.wrap(this, async (sids: number[]) => {
|
||||||
await loaded;
|
await fullyloaded;
|
||||||
Table.removedItems(sids);
|
Table.removedItems(sids);
|
||||||
});
|
}));
|
||||||
|
|
||||||
const statusNetwork = $("#statusNetwork");
|
const statusNetwork = $("#statusNetwork");
|
||||||
statusNetwork.addEventListener("click", () => {
|
statusNetwork.addEventListener("click", () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user