Browse Source

minor update to prevent redudant instantiation

Enzo 1 year ago
parent
commit
e0d7096dfe
1 changed files with 3 additions and 7 deletions
  1. 3 7
      services/message-auditor.service.ts

+ 3 - 7
services/message-auditor.service.ts

@@ -8,6 +8,7 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
     private settings: MessageSynchronisationServiceSetting
     private settings: MessageSynchronisationServiceSetting
     private sourceSrc: LoggingService = new LoggingService()
     private sourceSrc: LoggingService = new LoggingService()
     private targetSrc: LoggingService = new LoggingService()
     private targetSrc: LoggingService = new LoggingService()
+    private missingMessageSubject: Subject<MessageLog> = new Subject()
 
 
     /* Set up the targets or points of synchronization. This is where it will register the 2 different location of 
     /* Set up the targets or points of synchronization. This is where it will register the 2 different location of 
     the data to be synchronized */
     the data to be synchronized */
@@ -21,25 +22,20 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
     and return the missing data, which will then be passed into the targeted subject stream as specified by the
     and return the missing data, which will then be passed into the targeted subject stream as specified by the
     respective client. They can choose how they want to handle the missing messages returned. */
     respective client. They can choose how they want to handle the missing messages returned. */
     public subscribe(obsTrigger: Observable<ErrorTrigger>): Observable<MessageLog> {
     public subscribe(obsTrigger: Observable<ErrorTrigger>): Observable<MessageLog> {
-        // Create a subject as a means to return the missing messages if there's any.
-        let msg: Subject<MessageLog> = new Subject()
-
         // Subsribe to the errorTrigger obs to listen to any notification.
         // Subsribe to the errorTrigger obs to listen to any notification.
         obsTrigger.subscribe({
         obsTrigger.subscribe({
             next: obsTrigger => {
             next: obsTrigger => {
                 console.log(obsTrigger.message)// just checking the message
                 console.log(obsTrigger.message)// just checking the message
-
                 let missingMsg: Observable<MessageLog> = this.synchronize()
                 let missingMsg: Observable<MessageLog> = this.synchronize()
                 missingMsg.subscribe({
                 missingMsg.subscribe({
                     next: element => {
                     next: element => {
-                        msg.next(element)
+                        this.missingMessageSubject.next(element)
                         console.log(`AuditService: Returning missing messages ${element.appData.msgId} ....`)
                         console.log(`AuditService: Returning missing messages ${element.appData.msgId} ....`)
                     }
                     }
                 })
                 })
             }
             }
         })
         })
-        let result: Observable<MessageLog> = msg.asObservable()
-        return result
+        return this.missingMessageSubject
     }
     }
 
 
     /* This is where the 'synching' operation takes place. */
     /* This is where the 'synching' operation takes place. */