Currently, I am using a regular observable
instead of an observableArray
. This observable keeps an array of elements which is defined as follows:
public arrayOfItems: IArrayItem[];
public arrayOfItems$: BehaviorSubject<IArrayItem[]> = new BehaviorSubject<IArrayItem[]>(null);
public setArrayOfItems(arrayOfItems: IArrayItem[]): void {
this.arrayOfItems = arrayOfItems;
this.arrayOfItems$.next(arrayOfItems);
}
public getArrayOfItems(): Observable<IArrayItem[]> {
return this.arrayOfItems$.asObservable();
}
Now, I am looking to add a getSingleItemFromArray
method. The purpose of this method would be to retrieve a single element from arrayOfItems$
and I want the result to be returned as an Observable
as well. Here is a conceptual representation of what I have in mind:
public getSingleItemFromArray(): Observable<IArrayItem> {
return this.arrayOfItems$.find(item => item.condition).asObservable();
}
If there are any suggestions or guidance on how to implement this feature, please point me in the right direction.