add newEntries event
This commit is contained in:
		@@ -17,6 +17,7 @@ export class ListenerRss extends EventEmitter {
 | 
			
		||||
  // private fields
 | 
			
		||||
  parser: Parser;
 | 
			
		||||
  loopRunning: boolean = false;
 | 
			
		||||
  lastEntriesLinks: string[] = [];
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief constructor
 | 
			
		||||
@@ -66,7 +67,22 @@ export class ListenerRss extends EventEmitter {
 | 
			
		||||
 | 
			
		||||
    const fun: () => void = () => {
 | 
			
		||||
      this.fetchRSS()
 | 
			
		||||
        .then((obj: { [key: string]: any }) => this.emit("update", obj))
 | 
			
		||||
        .then((obj: { [key: string]: any }) => {
 | 
			
		||||
          this.emit("update", obj);
 | 
			
		||||
          const updatedEntriesLinks = obj.items.map(
 | 
			
		||||
            (item: { link: string }) => item.link
 | 
			
		||||
          );
 | 
			
		||||
 | 
			
		||||
          const newEntries = obj.items.filter(
 | 
			
		||||
            (item: { link: string }) =>
 | 
			
		||||
              !this.lastEntriesLinks.includes(item.link)
 | 
			
		||||
          );
 | 
			
		||||
 | 
			
		||||
          if (this.lastEntriesLinks.length !== 0 && newEntries.length !== 0) {
 | 
			
		||||
            this.emit("newEntries", newEntries);
 | 
			
		||||
          }
 | 
			
		||||
          this.lastEntriesLinks = updatedEntriesLinks;
 | 
			
		||||
        })
 | 
			
		||||
        .catch((err) => this.emit("error", err));
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user