private some fields and now newEntries is called only for the second update

This commit is contained in:
Amaury 2021-07-06 14:45:25 +02:00
parent 9c034a6100
commit fcf7c24b86

View File

@ -23,9 +23,10 @@ class ListenerRss extends EventEmitter {
customfields?: { [key: string]: string[] | string };
// private fields
parser: Parser;
loopRunning: boolean = false;
lastEntriesLinks: string[] = [];
private parser: Parser;
private loopRunning: boolean = false;
private lastEntriesLinks: string[] = [];
private firstUpdate = true;
/**
* @brief constructor
@ -89,10 +90,12 @@ class ListenerRss extends EventEmitter {
!this.lastEntriesLinks.includes(item.link)
);
if (newEntries.length !== 0) {
this.emit("newEntries", newEntries);
}
this.lastEntriesLinks = updatedEntriesLinks;
if (this.firstUpdate && newEntries.length !== 0)
this.emit("newEntries", newEntries);
this.firstUpdate = false;
})
.catch((err) => this.emit("error", err))
);