I am not so into RxJS and I have the following doubt about why it is the best way to solve this problem. I will try to explain it in details. Into a service class I have these 2 methods:
acceptArtistBid(bid): void {
this.findArtistBidsAppliedByCurrentWall(bid)
.subscribe(artistsBisdList => {
console.log("ARTISTS BIDS LIST RELATED THE CURRENT WALL: ", artistsBisdList);
// ITERATE ON EACH ELEMENT OF THE artistsBisdList, DO SOME CHANGE TO EACH ELEMENT AND UPDATE ALL THESE ELEEMENTS ON FIRESTORE
});
}
findArtistBidsAppliedByCurrentWall(bid):Observable<Bid[]> {
return this.db.collection('bids',
ref=> ref.where("wallId", "==", bid.wallId))
.snapshotChanges()
.pipe(
map(snaps => {
const courses = this.convertSnaps<Bid>(snaps);
return courses;
})
)
}
So basically I have this acceptArtistBid() method that call the findArtistBidsAppliedByCurrentWall() in order to retrieve an Observable containing a Bid objects array.
At the moment inside my acceptArtistBid() method I am subscribing this observable in order to retrieve the list of objects...then I have to iterate on this list in order to apply some logic to each of these object (I simply have to change the value of a status field) and then update these object on Firestore database.
Using this approach at the moment I was thinking to do a simple classical for loop interation or maybe the forEach() method passing an iterator function as parameter (as shown here: https://www.w3schools.com/js/js_array_iteration.asp) in order to change the status field value of each object in my array and then update these object on Firebase one by one.
I am asking if this approach is correct or if it is possible do something better using RxJS....in this case I think that I have not to subscribe my findArtistBidsAppliedByCurrentWall(bid) method but that maybe I have to use some RxJS operators directly on the Observable.
Is it possible? What could be an elegant solution using RxJS to solve this problem?