From fcf7c24b86a0ca16f917b5ad72315a09b9403b32 Mon Sep 17 00:00:00 2001 From: Amaury Date: Tue, 6 Jul 2021 14:45:25 +0200 Subject: [PATCH] private some fields and now newEntries is called only for the second update --- src/listener-rss.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/listener-rss.ts b/src/listener-rss.ts index 3dcddb4..4e8dcb7 100644 --- a/src/listener-rss.ts +++ b/src/listener-rss.ts @@ -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)) );