import { Injectable } from '@angular/core' ; import { Subject , Observable } from 'rxjs' ; import { ClockService } from './clock.service' ; export interface SystemEvent { toString ( ) : string ; } export interface LoggedEvent { time : number ; systemEvent : SystemEvent ; flushGroups : boolean ; } export class SystemEventGroupMark implements SystemEvent { startGroup : boolean ; systemEvent : SystemEvent ; constructor ( startGroup , systemEvent ) { this . startGroup = startGroup ; this . systemEvent = systemEvent ; } toString ( ) { return `-- event group mark --` ; } } @ Injectable ( ) export class EventsLogService { protected eventsLogSource = new Subject < LoggedEvent > ( ) ; public eventsLog$ : Observable < LoggedEvent > ; constructor ( private clockService ) { this . eventsLog$ = this . eventsLogSource . asObservable ( ) ; } public log ( systemEvent , flushGroups = false ) { const loggedEvent = { time : this . clockService . getClock ( ) , systemEvent : systemEvent , flushGroups : flushGroups } ; this . eventsLogSource . next ( loggedEvent ) ; } public startEventGroup ( systemEvent ) { const eventGroupMark = new SystemEventGroupMark ( true , systemEvent ) ; this . log ( eventGroupMark ) ; } public endEventGroup ( systemEvent ) { const eventGroupMark = new SystemEventGroupMark ( false , systemEvent ) ; this . log ( eventGroupMark ) ; } }