-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(firestore): add support for VectorValue #16476
Open
Lyokone
wants to merge
2
commits into
main
Choose a base branch
from
feat/vectorvalue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/cloud_firestore/cloud_firestore/example/integration_test/vector_value_e2e.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void runVectorValueTests() { | ||
group('$VectorValue', () { | ||
late FirebaseFirestore /*?*/ firestore; | ||
|
||
setUpAll(() async { | ||
firestore = FirebaseFirestore.instance; | ||
}); | ||
|
||
Future<DocumentReference<Map<String, dynamic>>> initializeTest( | ||
String path, | ||
) async { | ||
String prefixedPath = 'flutter-tests/$path'; | ||
await firestore.doc(prefixedPath).delete(); | ||
return firestore.doc(prefixedPath); | ||
} | ||
|
||
testWidgets('sets a $VectorValue & returns one', (_) async { | ||
DocumentReference<Map<String, dynamic>> doc = | ||
await initializeTest('vector-value'); | ||
|
||
await doc.set({ | ||
'foo': const VectorValue([10.0, -10.0]) | ||
}); | ||
|
||
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get(); | ||
|
||
VectorValue vectorValue = snapshot.data()!['foo']; | ||
expect(vectorValue, isA<VectorValue>()); | ||
expect(vectorValue.toArray(), equals([10.0, -10.0])); | ||
}); | ||
|
||
testWidgets('updates a $VectorValue & returns', (_) async { | ||
DocumentReference<Map<String, dynamic>> doc = | ||
await initializeTest('vector-value-update'); | ||
|
||
await doc.set({ | ||
'foo': const VectorValue([10.0, -10.0]) | ||
}); | ||
|
||
await doc.update({ | ||
'foo': const VectorValue([-10.0, 10.0]) | ||
}); | ||
|
||
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get(); | ||
|
||
VectorValue vectorValue = snapshot.data()!['foo']; | ||
expect(vectorValue, isA<VectorValue>()); | ||
expect(vectorValue.toArray(), equals([-10.0, 10.0])); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/vector_value.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ignore_for_file: require_trailing_commas | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
/// Represents a vector value by an array of doubles. | ||
@immutable | ||
class VectorValue { | ||
/// Create [VectorValue] instance. | ||
const VectorValue(this._value); | ||
|
||
final List<double> _value; // ignore: public_member_api_docs | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
other is VectorValue && listEquals(other._value, _value); | ||
|
||
@override | ||
int get hashCode => _value.hashCode; | ||
|
||
@override | ||
String toString() => 'VectorValue(value: $_value)'; | ||
|
||
/// Converts a [VectorValue] to a [List] of [double]. | ||
List<double> toArray() => _value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding e2e tests for potential edge cases, particularly for JS. For instance, not sure it would handle empty vector, single dimension, 2048 (maximum) dimensions, maximum dimensions + 1, very large values in vector, floats, negative values.