This commit is contained in:
2025-11-22 02:57:44 +01:00
parent 132d9e3d02
commit 79578e5daa
3 changed files with 34 additions and 7 deletions
+11 -1
View File
@@ -15,6 +15,8 @@ class DocumentsManager<T extends ManagedDocument = ManagedDocument> {
private listeners: Set<() => void>;
private emitScheduled: boolean;
constructor(
fetchDocument?: FetchDocument,
) {
@@ -22,10 +24,18 @@ class DocumentsManager<T extends ManagedDocument = ManagedDocument> {
this.fetcher = fetchDocument;
this.inflight = new Map();
this.listeners = new Set();
this.emitScheduled = false;
}
private emit() {
this.listeners.forEach((fn) => fn());
if (this.emitScheduled) {
return;
}
this.emitScheduled = true;
setTimeout(() => {
this.emitScheduled = false;
this.listeners.forEach((fn) => fn());
}, 0);
}
subscribe(listener: () => void) {