1- import { DocumentChangeType , CollectionReference , Query , DocumentReference } from '@firebase/firestore-types' ;
1+ import { DocumentChangeType , CollectionReference , Query , DocumentReference , DocumentData } from '@firebase/firestore-types' ;
22import { Observable , Subscriber } from 'rxjs' ;
33import { fromCollectionRef } from '../observable/fromRef' ;
44import { map , filter , scan } from 'rxjs/operators' ;
55
66import { Injectable } from '@angular/core' ;
77
8- import { QueryFn , AssociatedReference , DocumentChangeAction } from '../interfaces' ;
8+ import { QueryFn , AssociatedReference , DocumentChangeAction , DocumentChange } from '../interfaces' ;
99import { docChanges , sortedChanges } from './changes' ;
1010import { AngularFirestoreDocument } from '../document/document' ;
1111import { AngularFirestore } from '../firestore' ;
@@ -40,7 +40,7 @@ export function validateEventsArray(events?: DocumentChangeType[]) {
4040 * // Subscribe to changes as snapshots. This provides you data updates as well as delta updates.
4141 * fakeStock.valueChanges().subscribe(value => console.log(value));
4242 */
43- export class AngularFirestoreCollection < T > {
43+ export class AngularFirestoreCollection < T = DocumentData > {
4444 /**
4545 * The constructor takes in a CollectionReference and Query to provide wrapper methods
4646 * for data operations and data streaming.
@@ -62,17 +62,17 @@ export class AngularFirestoreCollection<T> {
6262 * your own data structure.
6363 * @param events
6464 */
65- stateChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
65+ stateChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
6666 if ( ! events || events . length === 0 ) {
6767 return this . afs . scheduler . keepUnstableUntilFirst (
6868 this . afs . scheduler . runOutsideAngular (
69- docChanges ( this . query )
69+ docChanges < T > ( this . query )
7070 )
7171 ) ;
7272 }
7373 return this . afs . scheduler . keepUnstableUntilFirst (
7474 this . afs . scheduler . runOutsideAngular (
75- docChanges ( this . query )
75+ docChanges < T > ( this . query )
7676 )
7777 )
7878 . pipe (
@@ -86,7 +86,7 @@ export class AngularFirestoreCollection<T> {
8686 * but it collects each event in an array over time.
8787 * @param events
8888 */
89- auditTrail ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
89+ auditTrail ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
9090 return this . stateChanges ( events ) . pipe ( scan ( ( current , action ) => [ ...current , ...action ] , [ ] ) ) ;
9191 }
9292
@@ -95,9 +95,9 @@ export class AngularFirestoreCollection<T> {
9595 * query order.
9696 * @param events
9797 */
98- snapshotChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
98+ snapshotChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
9999 const validatedEvents = validateEventsArray ( events ) ;
100- const sortedChanges$ = sortedChanges ( this . query , validatedEvents ) ;
100+ const sortedChanges$ = sortedChanges < T > ( this . query , validatedEvents ) ;
101101 const scheduledSortedChanges$ = this . afs . scheduler . runOutsideAngular ( sortedChanges$ ) ;
102102 return this . afs . scheduler . keepUnstableUntilFirst ( scheduledSortedChanges$ ) ;
103103 }
@@ -106,11 +106,11 @@ export class AngularFirestoreCollection<T> {
106106 * Listen to all documents in the collection and its possible query as an Observable.
107107 */
108108 valueChanges ( ) : Observable < T [ ] > {
109- const fromCollectionRef$ = fromCollectionRef ( this . query ) ;
109+ const fromCollectionRef$ = fromCollectionRef < T > ( this . query ) ;
110110 const scheduled$ = this . afs . scheduler . runOutsideAngular ( fromCollectionRef$ ) ;
111111 return this . afs . scheduler . keepUnstableUntilFirst ( scheduled$ )
112112 . pipe (
113- map ( actions => actions . payload . docs . map ( a => a . data ( ) ) as T [ ] )
113+ map ( actions => actions . payload . docs . map ( a => a . data ( ) ) )
114114 ) ;
115115 }
116116
0 commit comments