【发布时间】:2019-01-07 08:33:50
【问题描述】:
我正在尝试建立一个分页结果列表。我有循环工作,但我可以让 observable 发出最终结果。它循环完成,但从不发送到订阅。不确定使用 EMPTY 是否是错误的完成方式,或者是否因为 EMPTY 而未命中 reduce 并且永远不会触发最后一个结果?
getReportsAll(collection: Collection): Observable<PagedResult<ReportView>> {
return Observable.create(observer => {
this.collectionService.collectionBy(collection)
const url = this.collectionService.buildUrl(this.reportsUrl)
const newPage = new PagedResult<ReportView>([], null, null, 0)
this.getReportPage(url)
.pipe(
expand(result => {
const skip = collection.pageBy.skip + collection.pageBy.top
collection.pageBy = new PageBy(collection.pageBy.top, skip)
this.collectionService.collectionBy(collection)
const nextUrl = this.collectionService.buildUrl(this.reportsUrl)
const test = result.count >= collection.pageBy.top ? this.getReportPage(nextUrl) : EMPTY
console.log('test', test)
return test
}),
reduce((next: PagedResult<ReportView>, data: PagedResult<ReportView>, index: number) => {
next.value = [...next.value, ...data.value]
next.count = next.value.length
console.log('next', next, index)
return next
}, newPage),
)
// .catch(error => observer.error(error))
.subscribe(results => {
console.log('results', results)
})
})
}
【问题讨论】:
-
这里的 EMPTY 常量是什么?
-
它和 empty() 一样,应该在 observable 上触发一个 complete():rxjs-dev.firebaseapp.com/api/index/const/EMPTY