Skip to content

Commit

Permalink
feat: add GeoPoint toJSON() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehesp authored and mikehardy committed Jul 30, 2022
1 parent 8fb859f commit b062e74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/firestore/e2e/GeoPoint.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ describe('firestore.GeoPoint', function () {
equal.should.equal(true);
});
});

describe('toJSON()', function () {
it('returns a json representation of the GeoPoint', function () {
const geo = new firebase.firestore.GeoPoint(100, 200);
geo.toJSON().should.deepEqual({
latitude: 100,
longitude: 200,
});
});
});

it('sets & returns correctly', async function () {
const ref = firebase.firestore().doc(`${COLLECTION}/geopoint`);
await ref.set({
Expand Down
7 changes: 7 additions & 0 deletions packages/firestore/lib/FirestoreGeoPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ export default class FirestoreGeoPoint {

return this._latitude === other._latitude && this._longitude === other._longitude;
}

toJSON() {
return {
latitude: this._latitude,
longitude: this._longitude,
};
}
}
5 changes: 5 additions & 0 deletions packages/firestore/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,11 @@ export namespace FirebaseFirestoreTypes {
* @param other The `GeoPoint` to compare against.
*/
isEqual(other: GeoPoint): boolean;

/**
* Returns a JSON-serializable representation of this GeoPoint.
*/
toJSON(): { latitude: number; longitude: number };
}

/**
Expand Down

1 comment on commit b062e74

@vercel
Copy link

@vercel vercel bot commented on b062e74 Jul 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.