Skip to content

Commit

Permalink
fix(react-native-firebase): check if docChanges is an array
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Feb 17, 2019
1 parent 04f42be commit fc1622e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/GeoJoinerOnSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ export class GeoJoinerOnSnapshot {
* @param index Index of query who's snapshot has been triggered.
*/
private _processSnapshot(snapshot: GeoFirestoreTypes.web.QuerySnapshot, index: number): void {
const docChanges = Array.isArray(snapshot.docChanges) ?
snapshot.docChanges as any as GeoFirestoreTypes.web.DocumentChange[]: snapshot.docChanges();
if (!this._firstRoundResolved) this._queriesResolved[index] = 1;
if (snapshot.docChanges().length) { // Snapshot has data, key during first snapshot
snapshot.docChanges().forEach(change => {
if (docChanges.length) { // Snapshot has data, key during first snapshot
docChanges.forEach((change) => {
const distance = change.doc.data().l ? calculateDistance(this._queryCriteria.center, change.doc.data().l) : null;
const id = change.doc.id;
const fromMap = this._docs.get(id);
Expand Down
4 changes: 3 additions & 1 deletion src/GeoQuerySnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class GeoQuerySnapshot {
* @returns Array of DocumentChanges.
*/
public docChanges(): GeoFirestoreTypes.DocumentChange[] {
return (this._querySnapshot.docChanges() as GeoFirestoreTypes.web.DocumentChange[])
const docChanges = Array.isArray(this._querySnapshot.docChanges) ?
this._querySnapshot.docChanges as any as GeoFirestoreTypes.web.DocumentChange[]: this._querySnapshot.docChanges();
return (docChanges as GeoFirestoreTypes.web.DocumentChange[])
.map((change: GeoFirestoreTypes.web.DocumentChange) => {
return {
doc: generateGeoQueryDocumentSnapshot(change.doc, this._center),
Expand Down

0 comments on commit fc1622e

Please sign in to comment.