我試圖重構一些我編寫的代碼,然後合併所有可觀察對象以同時接收聊天對象。我使用角和離子和firebase。如何合併一系列可觀察對象內的觀察對象
this.userAsync = this.chatsProvider.getMyUserChatsGrpID().mergeMap(grpIDs=> {
if (grpIDs.length > 0) {
return Observable.combineLatest(
grpIDs.map((grpID) => this.chatsProvider.getGroupObjectAsync(grpID.$key).map(grpObject => {
grpObject.object = grpObject;
grpObject.memberProfiles = this.chatsProvider.getMemberProfiles(Object.keys(grpObject.members))
grpObject.latestMessage = this.chatsProvider.getLatestConversation(grpID.$key, grpObject.lastChecked)
grpObject.unreadMessages = this.chatsProvider.getUnreadMessageCount(grpID.$key, this.profileService.getUIDString())
return grpObject
})),
)
} else {
return Observable.of([])
}
目前這樣的代碼將返回然而,grpObject.memberprofiles,.lastestMessage,.unreadMessages返回爲可觀測量,然後我有使用一個異步管解開所需的對象。有沒有辦法將其全部轉換爲一個可觀察的項目?
但我仍然需要我的grpID。$ key來生成其餘的observables –