Skip to content

Commit 23a2424

Browse files
authored
Merge pull request #21 from eikooc/feature/generic
Make GeoFireCollectionRef generic
2 parents 25a06a9 + 971aa37 commit 23a2424

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

spec/main.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ describe('RxGeofire', () => {
6565
});
6666

6767
describe('CollectionRef', () => {
68-
let ref: GeoFireCollectionRef;
68+
let ref: GeoFireCollectionRef<any>;
6969
let hash;
7070
let phx;
7171
beforeEach(() => {
72-
ref = gfx.collection('cities');
72+
ref = gfx.collection<any>('cities');
7373
hash = gfx.point(33.45, -112.1);
7474
phx = { id: 'phoenix', name: 'Phoenix, AZ', position: hash.data };
7575
});
@@ -88,7 +88,7 @@ describe('RxGeofire', () => {
8888
});
8989

9090
test('should filter docs with a query and be able to change its query', done => {
91-
ref = gfx.collection('cities', ref =>
91+
ref = gfx.collection<any>('cities', ref =>
9292
ref.where('name', '==', 'Austin, TX')
9393
);
9494

@@ -158,12 +158,12 @@ describe('RxGeofire', () => {
158158
let ref: GeoFireCollectionRef;
159159
let center;
160160
beforeEach(() => {
161-
ref = gfx.collection('bearings');
161+
ref = gfx.collection<any>('bearings');
162162
center = gfx.point(40.5, -80.0);
163163
});
164164

165165
test('work with compound Firestore queries', async done => {
166-
const ref = gfx.collection('compound', ref =>
166+
const ref = gfx.collection<any>('compound', ref =>
167167
ref.where('color', '==', 'blue')
168168
);
169169
const point = gfx.point(38, -119);
@@ -239,7 +239,7 @@ describe('RxGeofire', () => {
239239
let center;
240240
let data;
241241
beforeAll(async () => {
242-
ref = gfx.collection('bearings');
242+
ref = gfx.collection<any>('bearings');
243243
center = gfx.point(40.5, -80.0);
244244
data = await get(ref.within(center, 5, 'pos'));
245245
});

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class GeoFireClient {
1212
* @param {QueryFn} query? Firestore query id ref => ref.orderBy('foo').limit(5)
1313
* @returns {GeoFireCollectionRef}
1414
*/
15-
collection(path: string, query?: QueryFn): GeoFireCollectionRef {
15+
collection<T>(path: string, query?: QueryFn): GeoFireCollectionRef<T> {
1616
return new GeoFireCollectionRef(this.app, path, query);
1717
}
1818
/**

src/collection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ export interface QueryMetadata {
1919
}
2020

2121
export interface GeoQueryDocument {
22-
[key: string]: any;
2322
queryMetadata: QueryMetadata;
2423
}
2524

26-
export class GeoFireCollectionRef {
25+
export class GeoFireCollectionRef<T> {
2726
private ref: firestore.CollectionReference;
2827
private query: firestore.Query;
2928
private stream: Observable<firestore.QuerySnapshot>;
@@ -120,7 +119,7 @@ export class GeoFireCollectionRef {
120119
radius: number,
121120
field: string,
122121
opts = defaultOpts
123-
): Observable<GeoQueryDocument[]> {
122+
): Observable<(GeoQueryDocument & T)[]> {
124123
const precision = setPrecsion(radius);
125124
const centerHash = center.hash.substr(0, precision);
126125
const area = GeoFirePoint.neighbors(centerHash).concat(centerHash);
@@ -147,7 +146,7 @@ export class GeoFireCollectionRef {
147146
distance: center.distance(lat, lng),
148147
bearing: center.bearing(lat, lng)
149148
};
150-
return { ...val, queryMetadata };
149+
return { ...val, queryMetadata } as (GeoQueryDocument & T);
151150
})
152151

153152
.sort((a, b) => a.queryMetadata.distance - b.queryMetadata.distance);

0 commit comments

Comments
 (0)