【发布时间】:2020-11-26 01:36:58
【问题描述】:
我有一个市场集合每个市场都有一个产品集合..我正在尝试查询以获取所有这些..我最终得到了一个解决方案,但我在第 9 行得到了关于 compineLatest 的提示“@deprecated — 改为在单个数组中传递参数"。
想知道有没有更好的abroach以及如何正确使用compineLatest。
//#region fetch method
private fetch(marketsRef: AngularFirestoreCollection<Market>) {
return marketsRef
.snapshotChanges()
.pipe(
switchMap(markets => {
if (!markets.length) {
this._noDataSubject$.next(true);
}
return combineLatest([markets],
combineLatest(
markets.map(market => {
return this.firestore.collection<MarketProduct>(`markets/${market.payload.doc.id}/products`, ref => {
return ref.orderBy('reviewResult')
})
.snapshotChanges()
})
)
)
}), map(([markets, products]) => {
const allProducts = products.reduce((acc, val) => acc.concat(val), []);
const returnedMarkets = markets.map(market => {
return {
id: market.payload.doc.id,
...market.payload.doc.data() as Market,
products: allProducts
.filter(product => product.payload.doc.ref.path === `markets/${market.payload.doc.id}/products/${product.payload.doc.id}`)
.map(product => {
return {
id: product.payload.doc.id,
...product.payload.doc.data() as MarketProduct
}
})
}
}) as MarketId[];
return returnedMarkets;
}))
}
//#endregion fetch method
//#region fetch new markets request
fetchNewMarkets() {
const key = `name.ar`;
const marketsRef = this.firestore.collection<Market>('markets', ref => {
return ref.where('reviewResult', '==', null).orderBy(key);
});
this.fetch(marketsRef)
.subscribe(markets => {
this._marketsChanges$.next(markets);
})
}
//#endregion fetch new markets request
【问题讨论】:
标签: javascript firebase google-cloud-firestore rxjs angularfire