In order to allow users to filter data by passing IDs, I have created a subject that can send an array of GUIDs:
selectedVacancies: Subject<string[]> = new Subject();
selectedVacancies.next(['a00652cd-c11e-465f-ac09-aa4d3ab056c9',
'f145b6a6-0a66-49d6-a2d2-eb9123061d96']);
I have another observable that subscribes to this subject and waits for the data (availableVacancies and availableVacancyTypes are Observables from my Angular service):
filteredVacancyTypes: Observable<VacancyTypeModel[]>;
filteredVacancyTypes = this.selectedVacancies
.flatMap(vacancyIds => vacancyIds)
.filter(id => !isNullOrUndefined(id))
.flatMap(id => this.availableVacancies.first(v => v.id === id))
.flatMap(v => this.availableVacancyTypes.filter(vt => vt.id === v.type.id))
I want to gather the filtered data and return it as an array of VacancyTypeModels. Although I am aware of the toArray method, I cannot use it because the subject is never completed (since I need to wait for more IDs to be published by the user).
Is there any way to return the data as an array without completing the source?