我正在寻找一种方法来链接RxJS Observables以在Angular应用程序中实现以下步骤:
我有一个Observable photoObservable
,它封装了相机组件关闭时完成的相机组件。
这是我到目前为止的代码片段。中间的Observable链是我在努力的地方:
private photoObservable: Observable; private photoObserver: Observer; cameraClosed() { this.photoObserver.complete(); } uploadPhotoFromCamera(data) { if (this.photoObservable == null) { this.photoObservable = new Observable((observer) => { this.photoObserver = observer; }); this.galleryService.putGallery(...) .mergeMap( returnedGallery => { // This where I need to upload photos as they are taken // Each upload will return an Observable }) .concatMap( returnedGallery => { this.galleryService.updateGallery(returnedGallery)); } .subscribe( returnedGallery => { log('Gallery updated!'); ); } this.photoObserver.next(data); }
我尝试过concat和concatMap,因为它们都依赖于之前的Observable在下一次运行之前完成,但我无法让它工作。
有没有办法使用RxJS运营商实现这一目标?在concat和forkjoin之间可能有某种混合吗?