From 865dfe3ed3a5ab329ac9b9711175df97e08c4f47 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:03:14 -0500 Subject: [PATCH 1/3] update isEquals --- .../src/lite-api/user_data_reader.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/firestore/src/lite-api/user_data_reader.ts b/packages/firestore/src/lite-api/user_data_reader.ts index 52313b2907a..008eb49809c 100644 --- a/packages/firestore/src/lite-api/user_data_reader.ts +++ b/packages/firestore/src/lite-api/user_data_reader.ts @@ -20,7 +20,7 @@ import { FieldPath as PublicFieldPath, SetOptions } from '@firebase/firestore-types'; -import { Compat, getModularInstance } from '@firebase/util'; +import { Compat, deepEqual, getModularInstance } from '@firebase/util'; import { ParseContext } from '../api/parse_context'; import { DatabaseId } from '../core/database_info'; @@ -525,13 +525,15 @@ export class ArrayUnionFieldValueImpl extends FieldValue { } isEqual(other: FieldValue): boolean { - // TODO(mrschmidt): Implement isEquals - return this === other; + return ( + other instanceof ArrayUnionFieldValueImpl && + deepEqual(this._elements, other._elements) + ); } } export class ArrayRemoveFieldValueImpl extends FieldValue { - constructor(methodName: string, readonly _elements: unknown[]) { + constructor(methodName: string, private readonly _elements: unknown[]) { super(methodName); } @@ -549,8 +551,10 @@ export class ArrayRemoveFieldValueImpl extends FieldValue { } isEqual(other: FieldValue): boolean { - // TODO(mrschmidt): Implement isEquals - return this === other; + return ( + other instanceof ArrayRemoveFieldValueImpl && + deepEqual(this._elements, other._elements) + ); } } @@ -568,8 +572,10 @@ export class NumericIncrementFieldValueImpl extends FieldValue { } isEqual(other: FieldValue): boolean { - // TODO(mrschmidt): Implement isEquals - return this === other; + return ( + other instanceof NumericIncrementFieldValueImpl && + this._operand === other._operand + ); } } From b4284ef4850d780191fe9776d40b0a205c81b650 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:35:55 -0500 Subject: [PATCH 2/3] Update integration.test.ts --- packages/firestore/test/lite/integration.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/firestore/test/lite/integration.test.ts b/packages/firestore/test/lite/integration.test.ts index 6d1e1393fa6..771c9c12d6e 100644 --- a/packages/firestore/test/lite/integration.test.ts +++ b/packages/firestore/test/lite/integration.test.ts @@ -883,6 +883,16 @@ describe('FieldValue', () => { expect(deleteField().isEqual(deleteField())).to.be.true; expect(serverTimestamp().isEqual(serverTimestamp())).to.be.true; expect(deleteField().isEqual(serverTimestamp())).to.be.false; + expect(arrayUnion().isEqual(arrayUnion())).to.be.true; + expect(arrayUnion('a').isEqual(arrayUnion('a'))).to.be.true; + expect(arrayUnion('a').isEqual(arrayUnion('b'))).to.be.false; + expect(arrayUnion('a', 'b').isEqual(arrayUnion('b', 'a'))).to.be.false; + expect(arrayRemove().isEqual(arrayRemove())).to.be.true; + expect(arrayRemove('a').isEqual(arrayRemove('a'))).to.be.true; + expect(arrayRemove('a').isEqual(arrayRemove('b'))).to.be.false; + expect(arrayRemove('a', 'b').isEqual(arrayRemove('b', 'a'))).to.be.false; + expect(increment(1).isEqual(increment(1))).to.be.true; + expect(increment(1).isEqual(increment(2))).to.be.false; }); it('support instanceof checks', () => { From 0f64eeb57720b63c3039373e7879f095576e0cd4 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:41:36 -0500 Subject: [PATCH 3/3] add changeset --- .changeset/yellow-houses-happen.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/yellow-houses-happen.md diff --git a/.changeset/yellow-houses-happen.md b/.changeset/yellow-houses-happen.md new file mode 100644 index 00000000000..66858c86adf --- /dev/null +++ b/.changeset/yellow-houses-happen.md @@ -0,0 +1,6 @@ +--- +'@firebase/firestore': patch +'firebase': patch +--- + +Update the `isEqual` function for arrayUnion, arrayRemove and increment.