Skip to content

Commit 2f855a6

Browse files
committed
fix(firestore): implement queryEqual modular API
1 parent f30a4fb commit 2f855a6

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ describe('firestore().collection().isEqual()', function () {
152152

153153
it('returns false when not equal (simple checks)', function () {
154154
const { getApp } = modular;
155-
const { getFirestore, collection, query, where, orderBy, limit } = firestoreModular;
155+
const { getFirestore, collection, query, where, orderBy, limit, queryEqual } =
156+
firestoreModular;
156157
const db = getFirestore();
157158
const secondaryDb = getFirestore(getApp('secondaryFromNative'));
158159

@@ -167,11 +168,11 @@ describe('firestore().collection().isEqual()', function () {
167168
const ref1 = query(collection(db, subCol), where('bar', '==', true));
168169
const ref2 = query(collection(db, subCol), where('bar', '==', true));
169170

170-
const eql1 = queryRef.isEqual(q1);
171-
const eql2 = queryRef.isEqual(q2);
172-
const eql3 = queryRef.isEqual(q3);
173-
const eql4 = queryRef.isEqual(q4);
174-
const eql5 = ref1.isEqual(ref2);
171+
const eql1 = queryEqual(queryRef, q1);
172+
const eql2 = queryEqual(queryRef, q2);
173+
const eql3 = queryEqual(queryRef, q3);
174+
const eql4 = queryEqual(queryRef, q4);
175+
const eql5 = queryEqual(ref1, ref2);
175176

176177
eql1.should.be.False();
177178
eql2.should.be.False();

packages/firestore/lib/modular/query.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,12 @@ export function getDocsFromServer(query) {
224224
export function deleteDoc(reference) {
225225
return reference.delete.call(reference, MODULAR_DEPRECATION_ARG);
226226
}
227+
228+
/**
229+
* @param {Query} left
230+
* @param {Query} right
231+
* @returns boolean true if left equals right
232+
*/
233+
export function queryEqual(left, right) {
234+
return left.isEqual.call(left, right, MODULAR_DEPRECATION_ARG);
235+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,16 @@ export function snapshotEqual<AppModelType, DbModelType extends DocumentData>(
214214
left: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>,
215215
right: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>,
216216
): boolean;
217+
218+
/**
219+
* Returns true if the provided queries point to the same collection and apply the same constraints.
220+
*
221+
* @param left Query<AppModelType, DbModelType> A Query to compare.
222+
* @param right Query<AppModelType, DbModelType> A Query to compare.
223+
*
224+
* @return boolean true if the references point to the same location in the same Firestore database.
225+
*/
226+
export declare function queryEqual<AppModelType, DbModelType extends DocumentData>(
227+
left: Query<AppModelType, DbModelType>,
228+
right: Query<AppModelType, DbModelType>,
229+
): boolean;

0 commit comments

Comments
 (0)