Skip to content

Commit 142e7ac

Browse files
committed
remove OnChanges lifecycle and prevent circular updates #445
1 parent 0044589 commit 142e7ac

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/app/modules/shared-filter/components/edit-fields/edit-fields.component.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
import { BasicField } from 'src/app/model/DataSelection/Profile/Fields/BasicFields/BasicField';
22
import { FieldsTreeAdapter } from 'src/app/shared/models/TreeNode/Adapter/FieldTreeAdapter';
3-
import { map, Subscription } from 'rxjs';
3+
import { map, Subscription, take } from 'rxjs';
44
import { SelectedBasicField } from 'src/app/model/DataSelection/Profile/Fields/BasicFields/SelectedBasicField';
5+
import { SelectedBasicFieldCloner } from 'src/app/model/Utilities/DataSelecionCloner/ProfileFields/SelectedFieldCloner';
56
import { SelectedProfileFieldsService } from 'src/app/service/DataSelection/SelectedProfileFields.service';
67
import { TreeNode } from 'src/app/shared/models/TreeNode/TreeNodeInterface';
7-
import {
8-
Component,
9-
EventEmitter,
10-
Input,
11-
OnChanges,
12-
OnDestroy,
13-
OnInit,
14-
Output,
15-
SimpleChanges,
16-
} from '@angular/core';
17-
import { SelectedBasicFieldCloner } from 'src/app/model/Utilities/DataSelecionCloner/ProfileFields/SelectedFieldCloner';
8+
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
189

1910
@Component({
2011
selector: 'num-edit-fields',
2112
templateUrl: './edit-fields.component.html',
2213
styleUrls: ['./edit-fields.component.scss'],
2314
providers: [SelectedProfileFieldsService],
2415
})
25-
export class EditFieldsComponent implements OnInit, OnChanges, OnDestroy {
16+
export class EditFieldsComponent implements OnInit, OnDestroy {
2617
@Input()
2718
fieldTree: BasicField[];
2819

@@ -38,9 +29,7 @@ export class EditFieldsComponent implements OnInit, OnChanges, OnDestroy {
3829
deepCopyFieldsSubscription: Subscription;
3930
constructor(private selectedDataSelectionProfileFieldsService: SelectedProfileFieldsService) {}
4031

41-
ngOnInit() {}
42-
43-
ngOnChanges(changes: SimpleChanges): void {
32+
ngOnInit() {
4433
this.traversAndUpddateTree();
4534
this.buildTreeFromProfileFields();
4635
}
@@ -55,6 +44,7 @@ export class EditFieldsComponent implements OnInit, OnChanges, OnDestroy {
5544
this.deepCopyFieldsSubscription = this.selectedDataSelectionProfileFieldsService
5645
.getDeepCopyBasicFields()
5746
.pipe(
47+
take(1),
5848
map((profileFields) => {
5949
this.setSelectedChildrenFields();
6050
this.tree = FieldsTreeAdapter.fromTree(profileFields);
@@ -122,7 +112,9 @@ export class EditFieldsComponent implements OnInit, OnChanges, OnDestroy {
122112
this.selectedBasicFields
123113
);
124114
this.updatedSelectedBasicFields.emit(clonedSelectedFields);
115+
// Only update the selection status, don't trigger tree rebuilding
125116
this.traversAndUpddateTree();
126-
this.selectedDataSelectionProfileFieldsService.setDeepCopyFields(this.fieldTree);
117+
// Remove this line that causes the circular trigger:
118+
// this.selectedDataSelectionProfileFieldsService.setDeepCopyFields(this.fieldTree);
127119
}
128120
}

0 commit comments

Comments
 (0)