This js reduce works fine to handle the query result:
function toc(current) {
return {....};
};
function getToc(data) {
return = data.reduce((a, c) => Object.assign(a, {[c.id]: toc(c)}), {});
};
const query = db.collection(normCollection)
.where('a_id', '==', a_id )
.where('year', '==', year)
.orderBy("id");
subscriptionNorm = collectionData(query, "id")
.subscribe(data => console.log(getToc(data)));
But when I use RxJs reduce, it stops working. It has something to do with the stream end, but ... But I do not understand how RxFire / RxJs handles a streamed firestore query result:
...
subscriptionNorm = collectionData(query, "id")
.pipe(reduce((a, c) => Object.assign(a, {[c.id]: toc(c)}), {}))
.subscribe(data => console.log(data));
Update this works fine, but ...:
...
subscriptionNorm = collectionData(query, "id")
.pipe(
map(v => v.reduce((a, c) =>
Object.assign(a, {[c.id]: toc(c)}), {})
),
)
.subscribe(data => console.log(data));