Skip to content

Commit f30a4fb

Browse files
committed
fix(firestore): implement refEqual modular API
1 parent 4aeae44 commit f30a4fb

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

packages/firestore/e2e/DocumentReference/isEqual.e2e.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ describe('firestore.doc().isEqual()', function () {
6363

6464
describe('modular', function () {
6565
it('throws if other is not a DocumentReference', function () {
66-
const { getFirestore, doc } = firestoreModular;
66+
const { getFirestore, doc, refEqual } = firestoreModular;
6767
try {
68-
doc(getFirestore(), 'bar/baz').isEqual(123);
68+
refEqual(doc(getFirestore(), 'bar/baz'), 123);
6969
return Promise.reject(new Error('Did not throw an Error.'));
7070
} catch (error) {
7171
error.message.should.containEql("'other' expected a DocumentReference instance");
@@ -74,27 +74,29 @@ describe('firestore.doc().isEqual()', function () {
7474
});
7575

7676
it('returns false when not equal', function () {
77-
const { getFirestore, doc } = firestoreModular;
77+
const { getApp } = modular;
78+
const { getFirestore, doc, refEqual } = firestoreModular;
7879
const db = getFirestore();
7980

8081
const docRef = doc(db, `${COLLECTION}/baz`);
8182

82-
const eql1 = docRef.isEqual(doc(db, `${COLLECTION}/foo`));
83-
const eql2 = docRef.isEqual(
84-
doc(getFirestore(firebase.app('secondaryFromNative')), `${COLLECTION}/baz`),
83+
const eql1 = refEqual(docRef, doc(db, `${COLLECTION}/foo`));
84+
const eql2 = refEqual(
85+
docRef,
86+
doc(getFirestore(getApp('secondaryFromNative')), `${COLLECTION}/baz`),
8587
);
8688

8789
eql1.should.be.False();
8890
eql2.should.be.False();
8991
});
9092

9193
it('returns true when equal', function () {
92-
const { getFirestore, doc } = firestoreModular;
94+
const { getFirestore, doc, refEqual } = firestoreModular;
9395
const db = getFirestore();
9496
const docRef = doc(db, `${COLLECTION}/baz`);
9597

96-
const eql1 = docRef.isEqual(docRef);
97-
const eql2 = docRef.isEqual(doc(db, `${COLLECTION}/baz`));
98+
const eql1 = refEqual(docRef, docRef);
99+
const eql2 = refEqual(docRef, doc(db, `${COLLECTION}/baz`));
98100

99101
eql1.should.be.True();
100102
eql2.should.be.True();

packages/firestore/e2e/Query/isEqual.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ describe('firestore().collection().isEqual()', function () {
140140

141141
describe('modular', function () {
142142
it('throws if other is not a Query', function () {
143-
const { getFirestore, collection } = firestoreModular;
143+
const { getFirestore, collection, refEqual } = firestoreModular;
144144
try {
145-
collection(getFirestore(), COLLECTION).isEqual(123);
145+
refEqual(collection(getFirestore(), COLLECTION), 123);
146146
return Promise.reject(new Error('Did not throw an Error.'));
147147
} catch (error) {
148148
error.message.should.containEql("'other' expected a Query instance");

packages/firestore/lib/modular/index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,22 @@ export function collection(
275275
...pathSegments: string[]
276276
): CollectionReference<DocumentData>;
277277

278+
/**
279+
*Returns true if the provided references are equal.
280+
*
281+
* @param left DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType> A reference to compare.
282+
* @param right DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType> A reference to compare.
283+
* @return boolean true if the references point to the same location in the same Firestore database.
284+
*/
285+
export declare function refEqual<AppModelType, DbModelType extends DocumentData>(
286+
left:
287+
| DocumentReference<AppModelType, DbModelType>
288+
| CollectionReference<AppModelType, DbModelType>,
289+
right:
290+
| DocumentReference<AppModelType, DbModelType>
291+
| CollectionReference<AppModelType, DbModelType>,
292+
): boolean;
293+
278294
/**
279295
* Creates and returns a new `Query` instance that includes all documents in the
280296
* database that are contained in a collection or subcollection with the

packages/firestore/lib/modular/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export function collection(parent, path, ...pathSegments) {
7171
return parent.collection.call(parent, path, MODULAR_DEPRECATION_ARG);
7272
}
7373

74+
/**
75+
* @param {DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>} left
76+
* @param {DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>} right
77+
* @return boolean true if the two references are equal
78+
*/
79+
export function refEqual(left, right) {
80+
return left.isEqual.call(left, right, MODULAR_DEPRECATION_ARG);
81+
}
82+
7483
/**
7584
* @param {Firestore} firestore
7685
* @param {string} collectionId

0 commit comments

Comments
 (0)