Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class DataReferenceComponent implements OnInit, OnDestroy {
dataRelationshipContext: any;
imagePosition: any;
showImageDescription: any;
private isUpdatingFromDataCallback = false;

constructor(
private angularPConnect: AngularPConnectService,
Expand All @@ -69,7 +70,30 @@ export class DataReferenceComponent implements OnInit, OnDestroy {
this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange);
this.children = this.pConn$.getChildren();
this.updateSelf();
}

ngOnDestroy(): void {
if (this.angularPConnectData.unsubscribeFn) {
this.angularPConnectData.unsubscribeFn();
}
}

// Callback passed when subscribing to store change
onStateChange() {
// 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();
}
}

getData() {
if (this.isUpdatingFromDataCallback) {
return;
}
if (
this.rawViewMetadata.config?.parameters &&
!this.isDDSourceDeferred &&
Expand All @@ -94,7 +118,9 @@ export class DataReferenceComponent implements OnInit, OnDestroy {
}))
.filter(item => item.key); // Filtering out undefined entries
this.dropDownDataSource = ddDataSource;
this.isUpdatingFromDataCallback = true;
this.updateSelf();
this.isUpdatingFromDataCallback = false;
} else {
const ddDataSource: any = [];
this.dropDownDataSource = ddDataSource;
Expand All @@ -110,24 +136,6 @@ export class DataReferenceComponent implements OnInit, OnDestroy {
}
}

ngOnDestroy(): void {
if (this.angularPConnectData.unsubscribeFn) {
this.angularPConnectData.unsubscribeFn();
}
}

// Callback passed when subscribing to store change
onStateChange() {
// 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() {
// Update properties based on configProps
const theConfigProps = this.pConn$.getConfigProps();
Expand Down Expand Up @@ -186,6 +194,7 @@ export class DataReferenceComponent implements OnInit, OnDestroy {

this.generateChildrenToRender();
this.displayChild = !(this.displaySingleRef || this.displayMultiRef);
this.getData();
}

updatePropertiesFromProps(theConfigProps) {
Expand Down
Loading