Skip to content

allow use of valuechanges for collectiongroup #2445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/firestore/collection-group/collection-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,27 @@ export class AngularFirestoreCollectionGroup<T=DocumentData> {

/**
* Listen to all documents in the collection and its possible query as an Observable.
*
* If the `idField` option is provided, document IDs are included and mapped to the
* provided `idField` property name.
* @param options
*/
valueChanges(): Observable<T[]> {
const fromCollectionRefScheduled$ = fromCollectionRef<T>(this.query, this.afs.schedulers.outsideAngular);
return fromCollectionRefScheduled$
valueChanges(): Observable<T[]>
valueChanges({}): Observable<T[]>
valueChanges<K extends string>(options: {idField: K}): Observable<(T & { [T in K]: string })[]>
valueChanges<K extends string>(options: {idField?: K} = {}): Observable<T[]> {
return fromCollectionRef<T>(this.query, this.afs.schedulers.outsideAngular)
.pipe(
map(actions => actions.payload.docs.map(a => a.data())),
map(actions => actions.payload.docs.map(a => {
if (options.idField) {
return {
...a.data() as Object,
...{ [options.idField]: a.id }
} as T & { [T in K]: string };
} else {
return a.data()
}
})),
this.afs.keepUnstableUntilFirst
);
}
Expand Down