Skip to content

Commit

Permalink
111768: move original code back to init only for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens Vannerum committed Feb 19, 2024
1 parent 9767260 commit f7f86b0
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
*/
ngOnInit() {
this.updatePageInfo(this.model.maxOptions, 1);
this.loadOptions();
this.loadOptions(true);
this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged())
.subscribe((value) => {
this.setCurrentValue(value);
});
}

loadOptions() {
loadOptions(fromInit: boolean) {
this.loading = true;
this.vocabularyService.getVocabularyEntriesByValue(this.inputText, false, this.model.vocabularyOptions, this.pageInfo).pipe(
getFirstSucceededRemoteDataPayload(),
catchError(() => observableOf(buildPaginatedList(new PageInfo(), []))),
tap(() => this.loading = false)
).subscribe((list: PaginatedList<VocabularyEntry>) => {
this.optionsList = list.page;
if (this.model.value) {
if (fromInit && this.model.value) {
this.setCurrentValue(this.model.value, true);
}

Expand All @@ -92,11 +96,6 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
this.selectedIndex = 0;
this.cdr.detectChanges();
});

this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged())
.subscribe((value) => {
this.setCurrentValue(value);
});
}

/**
Expand All @@ -113,7 +112,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
this.group.markAsUntouched();
this.inputText = null;
this.updatePageInfo(this.model.maxOptions, 1);
this.loadOptions();
this.loadOptions(false);
sdRef.open();
}
}
Expand Down Expand Up @@ -170,7 +169,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
this.inputText += keyName;
// When a new key is added, we need to reset the page info
this.updatePageInfo(this.model.maxOptions, 1);
this.loadOptions();
this.loadOptions(false);
}

removeKeyFromInput() {
Expand All @@ -179,7 +178,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
if (this.inputText === '') {
this.inputText = null;
}
this.loadOptions();
this.loadOptions(false);
}
}

Expand Down

0 comments on commit f7f86b0

Please sign in to comment.