arraysrxjsobservablerxfire

How do I convert an observable that emits an array into an observable that emits each value of the array individually?


I'm using RXFire and RXJS.

collectionData(firebase.firestore.collection('collectionname')).subscribe(x=>console.log(x)

returns

// [{document1}, {document2}]

What i'd like is an observable that returns

// {document1}
// {document2}

I've tried using a combination of from() and toArray() (i.e. converting the observable to a plain array and back to an observable that emits each document one by one) but toArray() only creates an observable that emits an array, not an actual array. I need an operation thats the OPPOSITE of toArray(). Take an observable that emits an array and turn it into an observable that emits each value individually.

How do I do that?


Edit:

I also tried doing something like

const newObs = oldObs.subscribe(x => from(x))

but that store the subscriber, not the new observable. =(


Solution

  • There are multiple ways to do that. For example:

    collectionData(firebase.firestore.collection('collectionname'))
      .pipe(
        concatAll(),
      )
      .subscribe();
    

    You can also use concatMap(array => array).

    Instead of concat* you can use merge* as well.