Skip to content

Commit f7f86b0

Browse files
author
Jens Vannerum
committed
111768: move original code back to init only for performance
1 parent 9767260 commit f7f86b0

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,22 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
6868
*/
6969
ngOnInit() {
7070
this.updatePageInfo(this.model.maxOptions, 1);
71-
this.loadOptions();
71+
this.loadOptions(true);
72+
this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged())
73+
.subscribe((value) => {
74+
this.setCurrentValue(value);
75+
});
7276
}
7377

74-
loadOptions() {
78+
loadOptions(fromInit: boolean) {
7579
this.loading = true;
7680
this.vocabularyService.getVocabularyEntriesByValue(this.inputText, false, this.model.vocabularyOptions, this.pageInfo).pipe(
7781
getFirstSucceededRemoteDataPayload(),
7882
catchError(() => observableOf(buildPaginatedList(new PageInfo(), []))),
7983
tap(() => this.loading = false)
8084
).subscribe((list: PaginatedList<VocabularyEntry>) => {
8185
this.optionsList = list.page;
82-
if (this.model.value) {
86+
if (fromInit && this.model.value) {
8387
this.setCurrentValue(this.model.value, true);
8488
}
8589

@@ -92,11 +96,6 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
9296
this.selectedIndex = 0;
9397
this.cdr.detectChanges();
9498
});
95-
96-
this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged())
97-
.subscribe((value) => {
98-
this.setCurrentValue(value);
99-
});
10099
}
101100

102101
/**
@@ -113,7 +112,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
113112
this.group.markAsUntouched();
114113
this.inputText = null;
115114
this.updatePageInfo(this.model.maxOptions, 1);
116-
this.loadOptions();
115+
this.loadOptions(false);
117116
sdRef.open();
118117
}
119118
}
@@ -170,7 +169,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
170169
this.inputText += keyName;
171170
// When a new key is added, we need to reset the page info
172171
this.updatePageInfo(this.model.maxOptions, 1);
173-
this.loadOptions();
172+
this.loadOptions(false);
174173
}
175174

176175
removeKeyFromInput() {
@@ -179,7 +178,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
179178
if (this.inputText === '') {
180179
this.inputText = null;
181180
}
182-
this.loadOptions();
181+
this.loadOptions(false);
183182
}
184183
}
185184

0 commit comments

Comments
 (0)