import { AuguryEvent } from '../../events' ; import { ComponentLifecycleMethodInvokedEvent } from '../../events/component-lifecycle-method-events' ; import { ZoneStabilizedEvent } from '../../events/zone' ; import { mergeComponentTrees } from '../../probes/types/component-tree-node' ; import { getComponentTypeChangeDetectionFrequency , getLifeCycleChecksPerComponentInstance , } from '../../probes/types/component-tree-node/merged-component-tree-node.functions' ; import { EventProjection } from '../event-projection.class' ; import { CollectedComponentTreeChangeEventData } from './collected-component-tree-change-event-data.interface' ; import { ComponentTreeChangesInfo } from './component-tree-changes-info.interface' ; export class ComponentTreeChangesInfoProjection extends EventProjection < ComponentTreeChangesInfo > { private result : CollectedComponentTreeChangeEventData = this . createInitialResultValue ( ) ; constructor ( private startEventId , private endEventId ) { super ( ) ; } public process ( event ) { if ( event . isInstanceOf ( ZoneStabilizedEvent ) ) { const zoneStabilizedEvent = event as ZoneStabilizedEvent ; if ( event . id < this . startEventId ) { this . result . previousComponentTree = zoneStabilizedEvent . componentTree ; } else if ( event . id >= this . endEventId ) { if ( this . result . nextComponentTree . length === 0 ) { this . result . nextComponentTree = zoneStabilizedEvent . componentTree ; } else { return true ; } } } else if ( event . isInstanceOf ( ComponentLifecycleMethodInvokedEvent ) && event . isIdInRange ( this . startEventId , this . endEventId ) ) { this . result . lifeCycleMethodInvokedEvents . push ( event as ComponentLifecycleMethodInvokedEvent ) ; } return false ; } protected getResult ( ) { const mergedComponentTree = mergeComponentTrees ( this . result . previousComponentTree , this . result . nextComponentTree ) ; const lifeCycleChecksPerComponentInstance = getLifeCycleChecksPerComponentInstance ( mergedComponentTree , this . result . lifeCycleMethodInvokedEvents ) ; return { mergedComponentTree , lifeCycleChecksPerComponentInstance , componentTypeChangeDetectionFrequencies : getComponentTypeChangeDetectionFrequency ( lifeCycleChecksPerComponentInstance ) , } ; } protected cleanup ( ) { this . result = this . createInitialResultValue ( ) ; } private createInitialResultValue ( ) { return { previousComponentTree : [ ] , nextComponentTree : [ ] , lifeCycleMethodInvokedEvents : [ ] , } ; } }