1
1
import * as firebase from 'firebase/app' ;
2
- import * as firestore from 'firestore' ;
3
2
import 'firestore' ;
4
- import { Firestore , CollectionReference , Query } from 'firestore' ;
3
+ import { Firestore , CollectionReference , Query , DocumentSnapshot , QuerySnapshot } from 'firestore' ;
5
4
import { Observable } from 'rxjs/Observable' ;
6
- import { Observer } from 'rxjs/Observer' ;
7
- import { Operator } from 'rxjs/Operator' ;
8
- import { Subscriber } from 'rxjs/Subscriber' ;
9
5
import { Subscription } from 'rxjs/Subscription' ;
10
6
11
7
import { Injectable } from '@angular/core' ;
@@ -19,7 +15,7 @@ export class AngularFirestore {
19
15
this . firestore = app . firestore ( ) ;
20
16
}
21
17
22
- collection ( path : string , queryFn : ( ref : CollectionReference ) => Query = ref => ref ) : Observable < firestore . QuerySnapshot > {
18
+ collection ( path : string , queryFn : ( ref : CollectionReference ) => Query = ref => ref ) : Observable < QuerySnapshot > {
23
19
const ref = this . firestore . collection ( path ) ;
24
20
const query = queryFn ( ref ) ;
25
21
return new Observable ( subscriber => {
@@ -28,60 +24,11 @@ export class AngularFirestore {
28
24
} ) ;
29
25
}
30
26
31
- doc ( path : string ) : Observable < firestore . DocumentSnapshot > {
27
+ doc ( path : string ) : Observable < DocumentSnapshot > {
32
28
const ref = this . firestore . doc ( path ) ;
33
29
return new Observable ( subscriber => {
34
30
const unsubscribe = ref . onSnapshot ( subscriber ) ;
35
31
return new Subscription ( unsubscribe ) ;
36
32
} ) ;
37
33
}
38
-
39
- }
40
-
41
- export class FirestoreDocumentReferenceObservable < T > extends Observable < T > {
42
- constructor ( public originalRef : firestore . DocumentReference , subscribe ?: < R > ( subscriber : Subscriber < R > ) => Subscription ) {
43
- super ( subscribe ) ;
44
- }
45
-
46
- lift < T , R > ( operator : Operator < T , R > ) : Observable < R > {
47
- const observable = new FirestoreDocumentReferenceObservable < R > ( this . originalRef ) ;
48
- observable . source = this ;
49
- observable . operator = operator ;
50
- observable . originalRef = this . originalRef ;
51
- return observable ;
52
- }
53
- }
54
-
55
- export class FirestoreCollectionReferenceObservable < T > extends Observable < T > {
56
- constructor ( public originalRef : firestore . CollectionReference , public query : firestore . Query , subscribe ?: < R > ( subscriber : Subscriber < R > ) => Subscription ) {
57
- super ( subscribe ) ;
58
- }
59
-
60
- lift < T , R > ( operator : Operator < T , R > ) : Observable < R > {
61
- const observable = new FirestoreCollectionReferenceObservable < R > ( this . originalRef , this . query ) ;
62
- observable . source = this ;
63
- observable . operator = operator ;
64
- observable . query = this . query ;
65
- observable . originalRef = this . originalRef ;
66
- return observable ;
67
- }
68
34
}
69
-
70
- /**
71
- * collection(path: string, queryFn: (ref: CollectionReference) => Query = ref => ref): Observable<firestore.QuerySnapshot> {
72
- const ref = this.firestore.collection(path);
73
- const query = queryFn(ref);
74
- return new FirestoreCollectionReferenceObservable(ref, query, subscriber => {
75
- const unsubscribe = query.onSnapshot(subscriber.next, subscriber.error, subscriber.complete);
76
- return new Subscription(unsubscribe);
77
- });
78
- }
79
-
80
- doc(path: string): Observable<firestore.DocumentSnapshot> {
81
- const ref = this.firestore.doc(path);
82
- return new FirestoreDocumentReferenceObservable(ref, subscriber => {
83
- const unsubscribe = ref.onSnapshot(subscriber.next, subscriber.error, subscriber.complete);
84
- return new Subscription(unsubscribe);
85
- });
86
- }
87
- */
0 commit comments