Здравствуйте. А не подскажите, можно ли как-то упростить поток который вызывает поиск на rxjs? Api может возвращеть null если не нашло записи. Спасибо.
export interface Organization {
code: string,
manager: string,
fullName: string,
name: string,
address: string,
activity: string,
status: string
}
private subscription = new Subscription();
constructor(private ufopService: UfopService) {
this.subscription.add(
this.searchText$.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap((code: string) => iif(
() => code.length === MIN_SEARCH_LENGTH,
this.ufopService.getOrganization(code).pipe(
switchMap((value: Organization | null) => iif(
() => value === null,
of(''),
of(value).pipe(
pluck('fullName')
))
)
),
of(''))
)
).subscribe(fullName => this.fullName = fullName)
)
}
onKeyPress(event: Event) {
const { value } = (event.target as HTMLInputElement);
this.searchText$.next(value)
}