import { Component, OnInit, Input, forwardRef, OnDestroy } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormGroup } from '@angular/forms'; import { AngularPConnectData, AngularPConnectService } from '@pega/angular-sdk-components'; import { ComponentMapperComponent } from '@pega/angular-sdk-components'; @Component({ selector: 'app-case-create-stage', templateUrl: './case-create-stage.component.html', styleUrls: ['./case-create-stage.component.scss'], imports: [CommonModule, forwardRef(() => ComponentMapperComponent)] }) export class CaseCreateStageComponent implements OnInit, OnDestroy { @Input() pConn$: typeof PConnect; @Input() formGroup$: FormGroup; arChildren$: any[]; // For interaction with AngularPConnect angularPConnectData: AngularPConnectData = {}; constructor(private angularPConnect: AngularPConnectService) {} ngOnInit(): void { // First thing in initialization is registering and subscribing to the AngularPConnect service this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange); // this.updateSelf(); this.checkAndUpdate(); } ngOnDestroy() { if (this.angularPConnectData.unsubscribeFn) { this.angularPConnectData.unsubscribeFn(); } } // Callback passed when subscribing to store change onStateChange() { this.checkAndUpdate(); } checkAndUpdate() { // Should always check the bridge to see if the component should // update itself (re-render) const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this); // ONLY call updateSelf when the component should update if (bUpdateSelf) { this.updateSelf(); } } updateSelf() { this.arChildren$ = this.pConn$.getChildren(); } }