1
- import { DocumentChangeType , CollectionReference , Query , DocumentReference } from '@firebase/firestore-types' ;
1
+ import { DocumentChangeType , CollectionReference , Query , DocumentReference , DocumentData } from '@firebase/firestore-types' ;
2
2
import { Observable , Subscriber } from 'rxjs' ;
3
3
import { fromCollectionRef } from '../observable/fromRef' ;
4
4
import { map , filter , scan } from 'rxjs/operators' ;
5
5
6
6
import { Injectable } from '@angular/core' ;
7
7
8
- import { QueryFn , AssociatedReference , DocumentChangeAction } from '../interfaces' ;
8
+ import { QueryFn , AssociatedReference , DocumentChangeAction , DocumentChange } from '../interfaces' ;
9
9
import { docChanges , sortedChanges } from './changes' ;
10
10
import { AngularFirestoreDocument } from '../document/document' ;
11
11
import { AngularFirestore } from '../firestore' ;
@@ -40,7 +40,7 @@ export function validateEventsArray(events?: DocumentChangeType[]) {
40
40
* // Subscribe to changes as snapshots. This provides you data updates as well as delta updates.
41
41
* fakeStock.valueChanges().subscribe(value => console.log(value));
42
42
*/
43
- export class AngularFirestoreCollection < T > {
43
+ export class AngularFirestoreCollection < T = DocumentData > {
44
44
/**
45
45
* The constructor takes in a CollectionReference and Query to provide wrapper methods
46
46
* for data operations and data streaming.
@@ -62,17 +62,17 @@ export class AngularFirestoreCollection<T> {
62
62
* your own data structure.
63
63
* @param events
64
64
*/
65
- stateChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
65
+ stateChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
66
66
if ( ! events || events . length === 0 ) {
67
67
return this . afs . scheduler . keepUnstableUntilFirst (
68
68
this . afs . scheduler . runOutsideAngular (
69
- docChanges ( this . query )
69
+ docChanges < T > ( this . query )
70
70
)
71
71
) ;
72
72
}
73
73
return this . afs . scheduler . keepUnstableUntilFirst (
74
74
this . afs . scheduler . runOutsideAngular (
75
- docChanges ( this . query )
75
+ docChanges < T > ( this . query )
76
76
)
77
77
)
78
78
. pipe (
@@ -86,7 +86,7 @@ export class AngularFirestoreCollection<T> {
86
86
* but it collects each event in an array over time.
87
87
* @param events
88
88
*/
89
- auditTrail ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
89
+ auditTrail ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
90
90
return this . stateChanges ( events ) . pipe ( scan ( ( current , action ) => [ ...current , ...action ] , [ ] ) ) ;
91
91
}
92
92
@@ -95,9 +95,9 @@ export class AngularFirestoreCollection<T> {
95
95
* query order.
96
96
* @param events
97
97
*/
98
- snapshotChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction [ ] > {
98
+ snapshotChanges ( events ?: DocumentChangeType [ ] ) : Observable < DocumentChangeAction < T > [ ] > {
99
99
const validatedEvents = validateEventsArray ( events ) ;
100
- const sortedChanges$ = sortedChanges ( this . query , validatedEvents ) ;
100
+ const sortedChanges$ = sortedChanges < T > ( this . query , validatedEvents ) ;
101
101
const scheduledSortedChanges$ = this . afs . scheduler . runOutsideAngular ( sortedChanges$ ) ;
102
102
return this . afs . scheduler . keepUnstableUntilFirst ( scheduledSortedChanges$ ) ;
103
103
}
@@ -106,11 +106,11 @@ export class AngularFirestoreCollection<T> {
106
106
* Listen to all documents in the collection and its possible query as an Observable.
107
107
*/
108
108
valueChanges ( ) : Observable < T [ ] > {
109
- const fromCollectionRef$ = fromCollectionRef ( this . query ) ;
109
+ const fromCollectionRef$ = fromCollectionRef < T > ( this . query ) ;
110
110
const scheduled$ = this . afs . scheduler . runOutsideAngular ( fromCollectionRef$ ) ;
111
111
return this . afs . scheduler . keepUnstableUntilFirst ( scheduled$ )
112
112
. pipe (
113
- map ( actions => actions . payload . docs . map ( a => a . data ( ) ) as T [ ] )
113
+ map ( actions => actions . payload . docs . map ( a => a . data ( ) ) )
114
114
) ;
115
115
}
116
116
0 commit comments