Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

后端 未结 3 1378
青春惊慌失措
青春惊慌失措 2020-12-16 06:01

I have created a Rx.Observable from a stream of events:

Rx.Observable.fromEvent(recognizeStream, \'data\')

In which every data

3条回答
  •  独厮守ぢ
    2020-12-16 06:23

    Operators flatMap() and concatMap() are both a good choice. You can just turn the alternatives property to another Observable and then emit the array items merged into the stream.

    const Observable = Rx.Observable;

    Observable.of({ error: null, alternatives: ['result1', 'result2', 'result3'] })
      .concatMap(val => {
        return Observable.from(val['alternatives']);
      })
      .subscribe(val => console.log(val));
    

    This prints to console:

    result1
    result2
    result3
    

    See live demo: https://jsbin.com/foqutab/2/edit?js,console

提交回复
热议问题