Skip to content

Commit d0d0729

Browse files
committed
feat(afs): keyValueChanges()
1 parent f1014ee commit d0d0729

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/firestore/collection/collection.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ export class AngularFirestoreCollection<T=DocumentData> {
113113
);
114114
}
115115

116+
/**
117+
* Listen to all documents in the collection and its possible query as an Observable.
118+
*/
119+
keyValueChanges(): Observable<{[key:string]: T}> {
120+
const fromCollectionRef$ = fromCollectionRef<T>(this.query);
121+
const scheduled$ = this.afs.scheduler.runOutsideAngular(fromCollectionRef$);
122+
return this.afs.scheduler.keepUnstableUntilFirst(scheduled$)
123+
.pipe(
124+
map(actions => actions.payload.docs.reduce((versions, action) => {
125+
versions[action.id] = action.data();
126+
return versions;
127+
}, {}))
128+
);
129+
}
130+
116131
/**
117132
* Add data to a collection reference.
118133
*

0 commit comments

Comments
 (0)