如何在从 frokJoin 订阅接收数据后发出可观察的

How to emit observable upon receiving data from frokJoin subscription

所以基本上我想用 forkJoin 从 3 个 observable 获取数据,一旦它们发出值,我想发出另一个 observable 表单订阅逻辑,这样我就可以从另一个地方订阅它。我现在拥有的

 getOptionsArray = <T>(): Observable<any> => {
    forkJoin([
      get1(),
      get2(),
      get3()
    ]).subscribe(([data1, data2, data3]) => {
      // some necessary assignment logic which needs to be here...

      // here I want to emit observable so I can subscribe to getOptionsArray method from 
      // another place, but only after logic in subcription here is applied.
    })
}

我知道我可以 return forkJoin 然后从另一个地方订阅它,但我需要先在这个函数中做一些赋值逻辑,然后再做一次应用此逻辑我想 return 可以从这个方法观察到我可以从另一个地方订阅。

您有 2 个选择:

getOptionsArray = <T>(): Observable<any> => {
    return forkJoin([
      get1(),
      get2(),
      get3()
    ]).pipe(map([data1, data2, data3]) => {
        ...
        return result;
    }))
}

getOptionsArray = <T>(): Observable<any> => {
    let subject = new Subject();
    forkJoin([
      get1(),
      get2(),
      get3()
    ]).subscribe(([data1, data2, data3]) => {
        ...
        subject.next(result);
        subject.completes();
    });
    return subject.asObservable();
}

我更喜欢第一个