|
1 |
| -import { FirebaseFirestore, CollectionReference } from '@firebase/firestore-types'; |
| 1 | +import { FirebaseFirestore, CollectionReference, DocumentReference } from '@firebase/firestore-types'; |
2 | 2 | import { Observable } from 'rxjs/Observable';
|
3 | 3 | import { Subscriber } from 'rxjs/Subscriber';
|
4 | 4 | import { from } from 'rxjs/observable/from';
|
@@ -106,25 +106,41 @@ export class AngularFirestore {
|
106 | 106 | }
|
107 | 107 |
|
108 | 108 | /**
|
109 |
| - * Create a reference to a Firestore Collection based on a path and an optional |
110 |
| - * query function to narrow the result set. |
111 |
| - * @param path |
| 109 | + * Create a reference to a Firestore Collection based on a path or |
| 110 | + * CollectionReference and an optional query function to narrow the result |
| 111 | + * set. |
| 112 | + * @param pathOrRef |
112 | 113 | * @param queryFn
|
113 | 114 | */
|
114 |
| - collection<T>(path: string, queryFn?: QueryFn): AngularFirestoreCollection<T> { |
115 |
| - const collectionRef = this.firestore.collection(path); |
| 115 | + collection<T>(path: string, queryFn?: QueryFn): AngularFirestoreCollection<T> |
| 116 | + collection<T>(ref: CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T> |
| 117 | + collection<T>(pathOrRef: string | CollectionReference, queryFn?: QueryFn): AngularFirestoreCollection<T> { |
| 118 | + let collectionRef: CollectionReference; |
| 119 | + if (typeof pathOrRef === 'string') { |
| 120 | + collectionRef = this.firestore.collection(pathOrRef); |
| 121 | + } else { |
| 122 | + collectionRef = pathOrRef; |
| 123 | + } |
116 | 124 | const { ref, query } = associateQuery(collectionRef, queryFn);
|
117 | 125 | return new AngularFirestoreCollection<T>(ref, query);
|
118 | 126 | }
|
119 | 127 |
|
120 | 128 | /**
|
121 |
| - * Create a reference to a Firestore Document based on a path. Note that documents |
122 |
| - * are not queryable because they are simply objects. However, documents have |
123 |
| - * sub-collections that return a Collection reference and can be queried. |
124 |
| - * @param path |
| 129 | + * Create a reference to a Firestore Document based on a path or |
| 130 | + * DocumentReference. Note that documents are not queryable because they are |
| 131 | + * simply objects. However, documents have sub-collections that return a |
| 132 | + * Collection reference and can be queried. |
| 133 | + * @param pathOrRef |
125 | 134 | */
|
126 |
| - doc<T>(path: string): AngularFirestoreDocument<T> { |
127 |
| - const ref = this.firestore.doc(path); |
| 135 | + doc<T>(path: string): AngularFirestoreDocument<T> |
| 136 | + doc<T>(ref: DocumentReference): AngularFirestoreDocument<T> |
| 137 | + doc<T>(pathOrRef: string | DocumentReference): AngularFirestoreDocument<T> { |
| 138 | + let ref: DocumentReference; |
| 139 | + if (typeof pathOrRef === 'string') { |
| 140 | + ref = this.firestore.doc(pathOrRef); |
| 141 | + } else { |
| 142 | + ref = pathOrRef; |
| 143 | + } |
128 | 144 | return new AngularFirestoreDocument<T>(ref);
|
129 | 145 | }
|
130 | 146 |
|
|
0 commit comments