Skip to content

[cloud_firestore] step 3 in landing FieldValue equality comparison (app-facing) #2063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
12ed4e2
Adds equality comparison to FieldValue
collinjackson Feb 25, 2020
3c40bc5
remove iOS files not intended to be changed
collinjackson Feb 25, 2020
709318e
Update CHANGELOG
collinjackson Feb 25, 2020
3200d39
Avoid a breaking change in the platform interface per suggestion from…
collinjackson Feb 25, 2020
b337942
Code review feedback
collinjackson Feb 25, 2020
0f7ab04
Fix test failures
collinjackson Feb 26, 2020
3531ed5
Remove assert
collinjackson Feb 26, 2020
c00e23c
Update comment
collinjackson Feb 26, 2020
048f545
Simplify FieldValue slightly
collinjackson Feb 26, 2020
92410e5
Reformat
collinjackson Feb 26, 2020
42ae413
Add deprecation warning
collinjackson Feb 26, 2020
3ea2d4b
Temporarily land path dependencies so that tests will pass
collinjackson Feb 26, 2020
7de25a0
Reformat
collinjackson Feb 26, 2020
c200793
Remove unused imports
collinjackson Feb 26, 2020
8bee0d8
Alas, the generic version is a breaking change. Leaving it as dynamic…
collinjackson Feb 26, 2020
4b71c23
Remove type argument from FieldValueFactoryWeb
collinjackson Feb 26, 2020
824c3e4
Reformat
collinjackson Feb 26, 2020
2396a83
Fix grammar in comment
collinjackson Feb 26, 2020
95aff27
Tweak comment
collinjackson Feb 26, 2020
f3177f5
update to published version
collinjackson Feb 26, 2020
796bcaf
Merge remote-tracking branch 'origin/master' into fieldvalue_equality_3
collinjackson Feb 26, 2020
2fbd7c9
update pubspec and CHANGELOG for release
collinjackson Feb 26, 2020
1fca852
Remove changes from commit that aren't landing in this change
collinjackson Feb 26, 2020
7edad76
Merge remote-tracking branch 'origin/master' into fieldvalue_equality_3
collinjackson Feb 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cloud_firestore/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,5 +493,17 @@ void main() {
children
.forEach((item) => expect(item, isInstanceOf<DocumentReference>()));
});

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)));
});
});
}
17 changes: 14 additions & 3 deletions packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions packages/cloud_firestore/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down