Add method to flush file events

This commit is contained in:
Silvano Cerza 2025-01-09 10:11:53 +01:00
parent 16459572a0
commit 7787a6f23b
2 changed files with 19 additions and 0 deletions

View file

@ -21,6 +21,13 @@ export default class EventsHandler {
this.vault.on("rename", this.onRename.bind(this));
}
/**
* Returns and empties the events queue.
*/
flush(): Event[] {
return this.eventsQueue.flush();
}
private async onCreate(file: TAbstractFile) {
if (!file.path.startsWith(this.localContentDir)) {
// The file has not been created in directory that we're syncing with GitHub

View file

@ -44,4 +44,16 @@ export default class EventsQueue {
this.eventsQueue.set(event.filePath, event);
}
}
/**
* Returns and empties the events queue.
*/
flush(): Event[] {
const events: Event[] = [];
this.eventsQueue.forEach((event) => {
events.push(event);
});
this.eventsQueue.clear();
return events;
}
}