diff --git a/packages/cloud_firestore/cloud_firestore/CHANGELOG.md b/packages/cloud_firestore/cloud_firestore/CHANGELOG.md index 369f4762edcf..6f166d499e32 100644 --- a/packages/cloud_firestore/cloud_firestore/CHANGELOG.md +++ b/packages/cloud_firestore/cloud_firestore/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.13.4 + +* Support equality comparison on `FieldValue` instances. +* Updated version of endorsed web implementation. + ## 0.13.3+1 * Make the pedantic dev_dependency explicit. diff --git a/packages/cloud_firestore/cloud_firestore/example/test_driver/cloud_firestore.dart b/packages/cloud_firestore/cloud_firestore/example/test_driver/cloud_firestore.dart index 8f23526b8f0d..da8629a382e2 100644 --- a/packages/cloud_firestore/cloud_firestore/example/test_driver/cloud_firestore.dart +++ b/packages/cloud_firestore/cloud_firestore/example/test_driver/cloud_firestore.dart @@ -493,5 +493,17 @@ void main() { children .forEach((item) => expect(item, isInstanceOf())); }); + + test('Equality comparison on FieldValues', () async { + final FieldValue arrayRemove = FieldValue.arrayRemove([1]); + expect(arrayRemove, equals(FieldValue.arrayRemove([1]))); + expect(arrayRemove, isNot(equals(FieldValue.arrayRemove([2])))); + final FieldValue delete = FieldValue.delete(); + expect(delete, equals(FieldValue.delete())); + expect(arrayRemove, isNot(equals(FieldValue.delete()))); + final FieldValue actualInt = FieldValue.increment(1); + final FieldValue actualDouble = FieldValue.increment(1.0); + expect(actualInt, isNot(equals(actualDouble))); + }); }); } diff --git a/packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart b/packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart index 4e1fb4f05940..25dbb3a827c0 100644 --- a/packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart +++ b/packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart @@ -14,9 +14,7 @@ class FieldValue extends platform.FieldValuePlatform { static final platform.FieldValueFactoryPlatform _factory = platform.FieldValueFactoryPlatform.instance; - FieldValue._(platform.FieldValuePlatform delegate) : super(delegate) { - platform.FieldValuePlatform.verifyExtends(delegate); - } + FieldValue._(this._delegate) : super(_delegate); /// Returns a special value that tells the server to union the given elements /// with any array value that already exists on the server. @@ -49,4 +47,17 @@ class FieldValue extends platform.FieldValuePlatform { /// server to increment the field’s current value by the given value. static FieldValue increment(num value) => FieldValue._(_factory.increment(value)); + + dynamic _delegate; + + @override + String toString() => '$runtimeType($_delegate)'; + + @override + bool operator ==(Object o) { + return o is FieldValue && o._delegate == _delegate; + } + + @override + int get hashCode => _delegate.hashCode; } diff --git a/packages/cloud_firestore/cloud_firestore/pubspec.yaml b/packages/cloud_firestore/cloud_firestore/pubspec.yaml index 0042b63cee91..875715fd8500 100755 --- a/packages/cloud_firestore/cloud_firestore/pubspec.yaml +++ b/packages/cloud_firestore/cloud_firestore/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database with live synchronization and offline support on Android and iOS. homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_firestore/cloud_firestore -version: 0.13.3+1 +version: 0.13.4 flutter: plugin: @@ -29,7 +29,7 @@ dependencies: # validation, so we set a ^ constraint. # TODO(amirh): Revisit this (either update this part in the design or the pub tool). # https://github.com/flutter/flutter/issues/46264 - cloud_firestore_web: ^0.1.0+1 + cloud_firestore_web: ^0.1.1 dev_dependencies: pedantic: ^1.8.0